posted 23 years ago
I've gotten a ways on this program, but am stuck as what I'm doing wrong. Here are my instructions:
/**
* Abstract class for quadrilater shape object.
* Corner numbers are from 1 to 4:
* 2 ---- 3
* | |
* 1 ---- 4
*/
public abstract class Quadrilateral {
// private attributes
private double x[] = new double[4];
private double y[] = new double[4];
// public methods
public double getArea() {
// fill in here
}
public double getX(int corner) {
return x[corner - 1];
}
public double getY(int corner) {
return y[corner - 1];
}
public double getPerimeter() {
// fill in here.
}
protected void setX(int corner, double value) {
x[corner - 1] = value;
}
protected void setY(int corner, double value) {
y[corner - 1] = value;
}
}
Create these class:
Class: Rectangle
Rectangle extends Quadrilateral.
Constructor:
public Rectangle( double lowerLeftX, double lowerLeftY,
double width, double height);
Class: Square
Square extends Quadrilateral.
Constructor:
public Square( double lowerLeftX, double lowerLeftY,
double side);
Create a TestQuad.java driver program that creates a
rectangle, square object and puts them
in a Quadrilateral[] array variable. Loop through the array
and print out the area, perimeter, and the corner positions
of shape.
Note that constructor for each concreate class is different.
End of Instructions
___________________________________-
Quadrilateral.java
Rectangle.java
Square.java
TestQuad.java
Here are the errors I'm getting, they are less than I was getting, but I'm not sure what I need to do now. Any suggestions would be great. Thanks
Errors:
C:\myjava\assignment3\problem1>javac Quadrilateral.java
Quadrilateral.java:25: 'class' or 'interface' expected
public double getX(int corner)
^
Quadrilateral.java:38: 'class' or 'interface' expected
}
^
Quadrilateral.java:47: 'class' or 'interface' expected
}
^
Quadrilateral.java:22: cannot resolve symbol
symbol : variable width
location: class Quadrilateral
return width*length;
^
Quadrilateral.java:22: cannot resolve symbol
symbol : variable length
location: class Quadrilateral
return width*length;
^
5 errors
------------------
Thanks, Dianne