I need help to create a class named rectangle that contains
-fields for length and width
-setters and getters for the fields
-a constructor that accepts length and width as parameters
-an overloaded 0-arg constructor that sets field values to 0
-a method named computeArea that accepts no parameters and returns the area
This is what I had so far:
Rectangle.java
public class Rectangle {
private double length;
private double width;
public void getLength(){
return length;
}
public void getWidth(){
return width;
}
public void setLength(double newLength){
this.length = newLength;
}
public void setWidth(double newWidth){
this.width = newWidth;
}
public Rectangle(double length, double width){
this.length = length;
this.width = width;
}
public Rectangle(){
length = 0;
width = 0;
}
double area = length * width;
public double computeArea(){
return area;
}
}
TestRectangle.java
public class TestRectangle{
public static void main(String[] arg){
Rectangle rect1 = new Rectangle();
rect1.setLength = 4.0;
rect1.setWidth = 5.0;
System.out.println("Length: " + rect1.getLength());
}
}