# Need Help. with two simple things

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• 04-28-2011, 01:06 AM
dlorde
Quote:

Originally Posted by Fred1
When i put this in my class circle it give me this error
double cannot be dereferenced

You need to use the Double class rather than the primitive double. With autoboxing, the conversion is just a simple cast these days:
Code:

```Circle c = (Circle)o; return ((Double)radius).compareTo(c.getRadius());```
• 04-28-2011, 01:10 AM
sunde887
Quote:

Originally Posted by dlorde
You need to use the Double class rather than the primitive double. With autoboxing, the conversion is just a simple cast these days:
Code:

```Circle c = (Circle)o; return ((Double)radius).compareTo(c.getRadius());```

Good catch, I completely missed that.

As clarification for the op, the double primitive is a primitive, you can't call methods on it, however; the Double class creates an object which allows you to call methods on a primitive with a simple cast, as shown above.
• 04-28-2011, 01:21 AM
Fred1
But on my testcircle to print out true and false for the equals method
Code:

```System.out.println("Circle1 equals Circle 2: " + circle1.equals(circle2)); System.out.println("Circle1 equals Circle 3: " + circle1.equals(circle3)); System.out.println("Circle2 equals Circle 3: " + circle2.equals(circle3));```
it gives me this error
circle1 is already defined in main(java.lang.String[])

and the same for circle 2 and 3 . if i put .equals(circle1) that do not work either so i dont know what to do from here
• 04-28-2011, 01:27 AM
dlorde
Sorry, I keep reading that as "my testicle" :)

I'm going to bed...
• 04-28-2011, 01:28 AM
Fred1
lol wow but its 8:30 here what time is it over there
• 04-28-2011, 01:30 AM
sunde887
Quote:

Originally Posted by dlorde
Sorry, I keep reading that as "my testicle" :)

I'm going to bed...

Lol, goodnight.

@op, would you mind posting the entire main method again?
• 04-28-2011, 01:44 AM
Fred1
Code:

``` //Listing 14.1 public abstract class GeometricObject {   private String color = "white";   private boolean filled;   private java.util.Date dateCreated;   /** Construct a default geometric object */   protected GeometricObject() {     dateCreated = new java.util.Date();   }   /** Construct a geometric object with color and filled value */   protected GeometricObject(String color, boolean filled) {     dateCreated = new java.util.Date();     this.color = color;     this.filled = filled;   }   /** Return color */   public String getColor() {     return color;   }   /** Set a new color */   public void setColor(String color) {     this.color = color;   }   /** Return filled. Since filled is boolean,   *  the get method is named isFilled */   public boolean isFilled() {     return filled;   }   /** Set a new filled */   public void setFilled(boolean filled) {     this.filled = filled;   }   /** Get dateCreated */   public java.util.Date getDateCreated() {     return dateCreated;   }   /** Return a string representation of this object */   public String toString() {     return "created on " + dateCreated + "\ncolor: " + color +       " and filled: " + filled;   }   /** Abstract method getArea */   public abstract double getArea();   /** Abstract method getPerimeter */   public abstract double getPerimeter(); }```
Code:

``` public class Circle extends GeometricObject {                                                           private double radius;                     public boolean equals(Circle Circle1)   {     return this.radius == Circle1.getRadius();   }                                     public int compareTo(Object o)                   {                   Circle c = (Circle)o;                 return ((double)radius).compareTo(c.getRadius());                   }                                   //Keep methods from Listing 14.2           public Circle() {           }           public Circle(double radius) {             this.radius = radius;           }           /** Return radius */           public double getRadius() {             return radius;         }           /** Set a new radius */           public void setRadius(double radius) {             this.radius = radius;           }           /** Return area */           public double getArea() {                 System.out.println("getArea() in Circle class.");             return radius * radius * Math.PI;           }           /** Return diameter */           public double getDiameter() {             return 2 * radius;           }           /** Return perimeter */           public double getPerimeter() {                   System.out.println("getPerimeter() in Circle class.");                      return 2 * radius * Math.PI;           }         /* Print the circle info */           public void printCircle() {             System.out.println("The circle is created " + getDateCreated() +               " and the radius is " + radius);           } }```

Code:

``` /**************************************** * * Student Name: LastName, FirstName MiddleName * Student Email: * Assignment number: * Date Due: * Date Submitted: * Program Name: TestCircle.java * Program Description: TestCircle.java * ****************************************/ public class TestCircle {                 public static void main(String[] args) {                         Circle circle1 = new Circle(3.0);                         Circle circle2 = new Circle(10.0);                         Circle circle3 = new Circle(3.0);                                                 String circle1 = new String("3.0");                         String circle2 = "10.0";                         String circle3 = "3.0";                                                 circle1.getColor();                         circle2.getColor();                         circle3.getColor();                                                 circle1.isFilled();                         circle2.isFilled();                         circle3.isFilled();                                                 circle1.getDateCreated();                         circle2.getDateCreated();                         circle3.getDateCreated();                                                                         System.out.println("Circle 1: radius = " + circle1.getRadius());                         System.out.println("Circle 2: radius = " + circle2.getRadius());                         System.out.println("Circle 3: radius = " + circle3.getRadius());                                                 System.out.println("Circle1 equals Circle 2: " + .equals(circle1));                         System.out.println("Circle1 equals Circle 3: " + circle1.equals(circle3));                         System.out.println("Circle2 equals Circle 3: " + circle2.equals(circle3));                                                 System.out.println("Circle1 compares to Circle2: " + circle1.compareTo(circle2));                         System.out.println("Circle1 compares to Circle3: " + circle1.compareTo(circle3));                         System.out.println("Circle2 compares to Circle3: " + circle2.compareTo(circle3));                                                                                 } }```
i need to get my equals to work .
• 04-28-2011, 01:46 AM
dlorde
System.out.println("Circle1 equals Circle 2: " + .equals(circle1));
• 04-28-2011, 01:47 AM
sunde887
In your main method, you declare three circles with the names circle1, circle2 and circle3, then you declare 3 strings with the same names. The compiler throws a fit when it sees this. Change the strings to has different names. Also, in our compareTo method you need to cast so Double, not double.
• 04-28-2011, 01:59 AM
Fred1
wow :) thank you guys for helping me. Dlorde sorry for keeping you up. sunde thanks for taking the time out to help. one last thing how do i make UMLs for these?
• 04-28-2011, 02:04 AM
sunde887
Umls are basically just charts which show the instance variables and methods a class contains and it shows dependencies as well. I suggest you google around to see some examples.
• 04-28-2011, 02:16 AM
Fred1
ok but is there like a website to go to
• 04-28-2011, 02:35 AM
sunde887
Not that I know off the top of my head, dream in code may have some uml stuff, also stack overflow may, but these are just guesses. I haven't done any uml so I don't really know sites for it.
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12