6 Replies - 3360 Views - Last Post: 28 February 2010 - 11:04 AM Rate Topic: -----

#1 LumberJack10  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 23
  • Joined: 27-February 10

Octagon Class

Posted 27 February 2010 - 02:56 PM

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);
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: Octagon Class

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9044
  • View blog
  • Posts: 33,551
  • Joined: 27-December 08

Re: Octagon Class

Posted 27 February 2010 - 02:59 PM

Please, :code:

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.
Was This Post Helpful? 1
  • +
  • -

#3 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 484
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

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

Was This Post Helpful? 1
  • +
  • -

#4 LumberJack10  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 23
  • Joined: 27-February 10

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);
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9044
  • View blog
  • Posts: 33,551
  • Joined: 27-December 08

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);.
Was This Post Helpful? 1
  • +
  • -

#6 LumberJack10  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 23
  • Joined: 27-February 10

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.
Was This Post Helpful? 0
  • +
  • -

#7 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 484
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

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
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1