I'm very new to Java, and I keep getting this compile error when trying to compile my code:
"MyRectangle.java:3: error: constructor Rectangle in class Rectangle cannot be applied to given types; Rectangle rectangle1 = new Rectangle(5.0, 10.0, "red"); ^ required: no arguments found: double,double,String reason: actual and formal argument lists differ in length
MyRectangle.java:8: error: constructor Rectangle in class Rectangle cannot be applied to given types; Rectangle rectangle2 = new Rectangle(3.5, 4.3, "yellow"); ^ required: no arguments found: double,double,String reason: actual and formal argument lists differ in length"
Here is my code:
public class MyRectangle {
public static void main (String[] args) {
Rectangle rectangle1 = new Rectangle(5.0, 10.0, "red");
System.out.println("The width of the first rectangle is " +
rectangle1.getWidth() +
" the height is " + rectangle1.getHeight() + " the area is " +
rectangle1.findArea() +
" and the color is " + rectangle1.getColor());
Rectangle rectangle2 = new Rectangle(3.5, 4.3, "yellow");
System.out.println("The width of the second rectangle is " +
rectangle2.getWidth() +
" the height is " + rectangle2.getHeight() + " the area is " +
rectangle2.findArea() +
" and the color is " + rectangle2.getColor());
}
}
class Rectangle {
private double width = 1.0;
private double height = 1.0;
private static String color = "white";
public double MyRectangle(){
}
public double MyRectangle(double widthParam, double heightParam, String
colorParam){
}
public double getWidth(){
return width;
}
public void setWidth(double widthParam){
width = widthParam;
}
public double getHeight(){
return height;
}
public void setHeight(double heightParam){
height = heightParam;
}
public String getColor(){
return color;
}
public static void setColor(String colorParam){
color = colorParam;
}
public double findArea(){
return width * height;
}
}