public class Circle extends GeometricObject implements Comparable<Circle>
{
private int radius;
public Circle(int newRadius)
{
radius=newRadius;
[Code] ....
When I run the driver class it tells me that all tests have passed(as it should be) except for Test 0. I have tried to play around with the code, but I cant figure it out and it is driving me crazy because in my head my code makes sense.
I am working on a random circles program. Basically it is supposed to draw as many random circles as you tell it to, 1-20. I have it drawing circles but it only draws twenty no matter what I type in. Here is my code for the component:
I have created two classes. The FrameViewer is my driver class, and Circle is my constructor.
The first problem is, the program seems to be creating both circles, but it only displays displaying the last added circle (in this case, circle2).
The second problem is, I want to pass the color I wish to use to the constructor, but I'm having problems figuring out the proper method to do so. In the constructor, I have assigned Color.BLUE as a default. On circle two, I want to override this color choice and assign Color.Orange. I am not having any luck setting this to work either.
import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Color; public class FrameViewer { public static void main(String[] args) { JFrame frame = new JFrame();
You should write a class that represents a circle object and includes the following:
1. Private class variables that store the radius and centre coordinates of the object. 2. Constructors to create circle objects with nothing supplied, with just a radius value supplied and with a radius and centre coordinates supplied. 3. Public instance methods that allow the radius and centre coordinates to be set and retrieved (often known as set/get methods). 4. Public instance methods that return the circumference and area of the circle. 5. A public class method that tests if two circle objects overlap or not
Here is my code:
import java.lang.Math; public class Circle { private double xCentre, yCentre, Radius; // constructors public Circle() { xCentre = 0.0; yCentre = 0.0; Radius = 1.0;
[Code] ....
The second program just has to demonstrate each aspect addressed in the brief I pasted at the top.s of what else I can do.
This is as far as I got during the 3 hour lab session I had and both compiled fine but when running just displayed all the text eg. "Circumference of first circle is ", but didn't display any numeric values. I don't have the facilities to actually run the program unless I'm in the computer lab, I have a short opportunity to go in tomorrow but that will be the last so I'm doubtful that I'll get it fully working in time.
The problem is that when this code runs it doesn't display any numerical values, ie nothing is being passed between the two programs.
Write a program that draws 20 circles, with the radius and location of each circle determined at random...... Two circles overlap if the distance between their center points is less than the sum of their radii...
There may be many problems with the code in general but what I'm struggling with is the distance and the totalradius portion. Visually, its inaccurate.
import java.awt.*; import javax.swing.*; public class CircleTest extends JPanel { Circle []circles; Circle []circleCenter; Circle []all; private int distance, totalradius, dx, dy; private int radius,x,y;
Its supposed to notify the user if they have a palindrome, but keeps returning true even when I type, "hello".
import java.util.Scanner; public class PalinDrome { public static void main(String[] args) { String line; Scanner input = new Scanner(System.in); System.out.print("Please enter a word ");
I'm trying to get the input of two jcomboBoxes for example if jcombobox 1 option 1 and jcombox box 2 option 1 is selected result = x
Here is my code:
comboDest1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // // Get the source of the component, which is our combo box. // JComboBox comboDest1 = (JComboBox) event.getSource();
how can i compare date with following request the value date transction must be within the Active date(>= greater than or equal) and inactive date(<= less than) date range
public class Item{ private int myId; private int myInv; public Item(int id, int inv){ myId = id; myInv = inv;
[Code] .....
I do not understand how to complete the compareTo() method and the equals() method. I understand that the compareTo() to should return 1 if the argument is smaller -1 if its bigger and 0 if they are the same, but I do not understand how it's possible to compare the current object with the object passed in as the parameter.
This is what I tried for the compareTo():
public int compareTo(Item other){ return this.compareTo(other); }
But my compiler tells me its a recursive call so I am not sure if I am doing this correctly.
Basically I am supposed to compare an object to another but I am not sure how to access the object that is not passed in as a parameter and compare it. Same goes for the equals(). This is what I tried for that (compiler also says its a recursive call):
public boolean equals(Item other){ return this.equals(other); }
I have a ArrayList of objects of class called HockeyPlayer (ArrayList<HockeyPlayer>). A HockeyPlayer has a String name and int number of goals.
This is my current work for comparing each object in the list to every other and printing them to screen:
Iterator<HockeyPlayer> it = hockeyPlayersList.iterator(); while (it.hasNext()) { HockeyPlayer singleHockeyPlayer = it.next(); //the first one encountered // HockeyPlayer nextHockeyPlayer = it.next(); //the next one encountered
[Code]...
This of course produces some duplication in the print-out: These are the equal hockey players: Who Ever wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.
Jason Harrison wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.
These are the equal hockey players: Jason Harrison wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.
Who Ever wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.
I could get my session values in my jsp, now I want to compare the session value whether it matches the textbox, if it matches, it will redirect the user to another page else it will remain the same page.
So I am trying to create a code that searches if a word is square free. The user inputs a word (into an array) and then the code is suppose to see if it is square free. A word being square free means that the word doesn't contain any consecutive sub words. For example, "abcabc" is not a square free word because abc is repeated, but "abcdabc" is a square free word because there is a "d" separating the "abc".
So far I have this :
import java.util.Scanner; public class A3Q2 { public static void main(String[] args) { // part (a) of the main Scanner keyboard = new Scanner(System.in);
[Code] ....
I've been trying to experiment with different ways such as checking to see if there any duplicate elements such as,
public static char isSquareFree(char[] word){ for(char i = 1; i < word.length; i++) { if(word[i] == word[i - 'a']) { System.out.println("Duplicate: " + word[i]); } } return word; } }
I want to make a program in which i write the Months Strings via while into the checkbox.
I already did that but i have also to add an day if February is a loop day.
So my question is how to say java that if Months is equal to February & year is a leap year, add 1. (i didn't wrote the year code because it's not relevant for my problem.)
Java Code:
public String[] Months ={"January","February","March","April","May", "June", "July", "August", "September", "Oktober", "November", "December"}; public Asg1KeapYear() { initComponents(); int MonthNo = 0;
[Code] ....
Netbeans shows me .equals() on incompatible types on Months.equals, do i have to declare it somehow?
>Suppose that aList and bList are instances of java.util.ArrayList. Use two iterators to find and display all the objects that are common to both lists. Do not alter the contents of either list. Write the segment of code assuming that the objects are of type String.
If my understanding is correct, I need to create two Iterators (one for aList and one for bList) to compare both ArrayLists and I should output any value that appears in both lists.
This is my attempt at it:
import java.util.ArrayList; public class Test { public static void main(String[] args) { ArrayList<String> aList = new ArrayList<String>(); ArrayList<String> bList = new ArrayList<String>();
aList.add("One"); aList.add("Two");
[Code] ....
The output:
`One`
`Two`
It stops there. It's clear that my loop is wrong, but I don't really know how to go about fixing it.
Is there a different logic in Java for if statements when it comes to conditions? I mean my attempt to compare a String variable and a String attribute of a class that is on an array of objects was frustrated someway. It will not enter the if block. The two strings are equal. I displayed the values of each strings before the if evaluation and they are equal. The simbol I used was the ==, and I also tried the string.equals(string variable) as well as the compareTo() == 0 option but none of those worked. I wish I knew what it is the way to compare two strings.