I am creating a object class called Octagon that implements Comparable and Cloneable interface.
Im getting a lot of errors and i do not know whats going on.
import java.util.Scanner;
public class extends GeometricObject implements Cloneable Comparable {
private double width;
private double height;
public Octagon.java() {
width = 0.0;
height = 0.0;
}
public Octagon(double width, double height){
this.width = width;
this.height = height;
}
/**Return Width*/
public double getWidth(){
return width;
}
/**Set new width*/
public void setWidth(double width){
this.width = width;
}
/**Return height*/
public double getheight() {
return height;
}
/**Set a new height */
public void setHeight(double height){
this.height = height;
}
/**Return area*/
public double getArea(){
return ((2 + 4/Math.sqrt(2))side * side);
}
/**Return Perimeter */
public double getPerimeter(){
return 2 * (width + height);
}
}
Octagon ClassHelp
Page 1 of 1
6 Replies - 3360 Views - Last Post: 28 February 2010 - 11:04 AM
Replies To: Octagon Class
#2
Re: Octagon Class
Posted 27 February 2010 - 02:59 PM
Please, 
Here, you need to define the class name in addition to separating the interfaces by commas, like so:
In the constructor, you need to remove the .java extension:
And lastly, you need to implement the compareTo() method from the Comparable interface or declare your Octagon class as abstract.
Here, you need to define the class name in addition to separating the interfaces by commas, like so:
public class Octagon extends GeometricObject implements Cloneable, Comparable
In the constructor, you need to remove the .java extension:
public Octagon.java(){
And lastly, you need to implement the compareTo() method from the Comparable interface or declare your Octagon class as abstract.
#3
Re: Octagon Class
Posted 27 February 2010 - 03:02 PM
public class extends GeometricObject implements Cloneable Comparable {
You are telling the compiler that your class is called 'extends', which isn't valid, since extends is a keyword.
edit: oops, sorry macosxnerd101, didn't see that you already commented on that error
This post has been edited by erik.price: 27 February 2010 - 03:03 PM
#4
Re: Octagon Class
Posted 27 February 2010 - 03:15 PM
Thanks Guys
I have one more question though, the compiler hates this statement.
return ((2 + 4 / Math.sqrt(2))side * side);
I have one more question though, the compiler hates this statement.
return ((2 + 4 / Math.sqrt(2))side * side);
#5
Re: Octagon Class
Posted 27 February 2010 - 03:19 PM
Unlike in math, having (term)(term) does not mean multiply. If you want an operation to be performed, you have to specify it. So that line should be:
return ((2 + 4 / Math.sqrt(2))*side * side);.
return ((2 + 4 / Math.sqrt(2))*side * side);.
#6
Re: Octagon Class
Posted 28 February 2010 - 10:56 AM
I pretty much have it completed.
How would you suggest making it interactive? Just a normal System.out.print or is there another way.
I'm making it interactive so the user can put in the length of the sides.
How would you suggest making it interactive? Just a normal System.out.print or is there another way.
I'm making it interactive so the user can put in the length of the sides.
#7
Re: Octagon Class
Posted 28 February 2010 - 11:04 AM
A combination of Scanner and print statements would be fine for making it interactive.
You could also look into making it more visual, with something like a JOptionPane
You could also look into making it more visual, with something like a JOptionPane
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|