Invalid method declaration, return type required

Posted by Brett Steen on Stack Overflow See other posts from Stack Overflow or by Brett Steen
Published on 2012-11-20T22:55:07Z Indexed on 2012/11/20 22:59 UTC
Read the original article Hit count: 272

Filed under:

I am getting an error at public Rectangle(double width, double height){ saying that it's an invalid method declaration, return type required. I'm not sure how to fix it. These are also my instructions for my assignment: Write a super class encapsulating a rectangle. A rectangle has two attributes representing the width and the height of the rectangle. It has methods returning the perimeter and the area of the rectangle. This class has a subclass, encapsulating a parallelepiped, or box. A parallelepiped has a rectangle as its base, and another attribute, its length. It has two methods that calculate and return its area and volume.

`public class Rectangle1
{

private double width;
private double height;

public Rectangle1(){
}

public Rectangle(double width, double height){
this.width = width;
this.height = height;

}

public double getWidth(){
return width;
}

public void setWidth(double width) {
this.width = width;

}


public double getHeight(){
return height;

}

public void setHeight(double height){
this.height = height;

}

public double getArea(){
return width * height;
}

public double getPerimeter(){
return 2 * (width + height);

}

}



public class TestRectangle {

public static void main(String[] args) {

Rectangle1 rectangle = new Rectangle1(2,4);

System.out.println("\nA rectangle " + rectangle.toString());
System.out.println("The area is " + rectangle.getArea());
System.out.println("The perimeter is " +
rectangle.getPerimeter());
}
}`

© Stack Overflow or respective owner

Related posts about java