For the Cube
class, i am trying to get rid of the error:
Cube.java:12: error: constructor Rectangle in class Rectangle cannot be applied to given types;
super(x, y);
^
required: int,int,double,double
found: int,int.......
I know each face of a Cube is a Rectangle whose length and width need to be the same as the side of a Cube but I am not sure what needs to be passed to the Rectangle constructor to make its length and width be the same as the side of a Cube.
also trying to calculate the volume which is the area of the rectangle times the length of the Cubes sides
This is the Cube class
// ---------------------------------
// File Description:
// Defines a Cube
// ---------------------------------
public class Cube extends Rectangle
{
public Cube(int x, int y, int side)
{
super(x, y);
side = super.area(); // not sure if this is right
}
public int getSide() {return side;}
public double area() {return 6 * super.area();}
public double volume() {return super.area() * side;}
public String toString() {return super.toString();}
}
and this is the rectangle class
// ---------------------------------
// File Description:
// Defines a Rectangle
// ---------------------------------
public class Rectangle extends Point
{
private int x, y; // Coordinates of the Point
private double length, width;
public Rectangle(int x, int y, double l, double w)
{
super(x, y);
length = l;
width = w;
}
public int getX() {return x;}
public int getY() {return y;}
public double getLength() {return length;}
public double getWidth() {return width;}
public double area() {return length * width;}
public String toString() {return "[" + x + ", " + y + "]" + " Length = " + length + " Width = " + width;}
}
Rectangle
doesn't have a constructor that takes 2 arguments, what code do you expect to be called when you invokesuper(x, y);
?Cube
needs to inherit fromRectangle
and not simply hold an array ofRectangles
, each with its ownPoint
and length? Also, sinceRectangle
extendsPoint
, you need not definex
,y
,getX
orgetY
inRectangle
- you inherit these properties.