Help, zit helemaal vast vlak voor mijn tentamens! Het probleem:
Ik moet dus een client program maken om een class te testen.
De class is:
(komt uit het boek: introduction to java programming, schrijver: Y.D.Liang)
alvast bedankt
Ik moet dus een client program maken om een class te testen.
De class is:
en de 'zelfgemaakte' test programma:public class Rectangle
{
private double width;
private double height;
// Default constructor
public Rectangle()
{
this(1.0, 1.0);
}
// Construct a rectangle with specified width and height
public Rectangle(double width, double height)
{
this.width = width;
this.height = height;
}
// Getter method for width
public double getWidth()
{
return width;
}
// Setter method for width
public void setWidth(double width)
{
this.width = width;
}
// Getter method for height
public double getHeight()
{
return height;
}
// Setter method for height
public void setHeight(double height)
{
this.height = height;
}
// Implement the findArea method in GeometricObject
public double findArea()
{
return width*height;
}
}
Dit is de compiler output, als ik One.java probeer te compileren:public class One
{
Rectangle rect1 = new Rectangle();
rect1.setWidth(5.0);
System.out.println(rect1.getWidth());
}
Ik heb alles al geprobeerd, maar ik kom er niet uit, kan iemand me alsjeblieft helpen?One.java:5: Type expected.
rect1.setWidth(5.0);
^
1 error
(komt uit het boek: introduction to java programming, schrijver: Y.D.Liang)
alvast bedankt