when i tried to call My Rectangle class after compiling it, it gives me some kin
ID: 3647206 • Letter: W
Question
when i tried to call My Rectangle class after compiling it, it gives me some king of java.lang.NoSuchMethodError.It compiles fines,but gives error when tried to run.Can anyone fix this.here is code:
class MyRectangle
{
private double width = 1.0;
private double height = 1.0;
private static String color ="white";
public MyRectangle()
{
width = 1.0;
height = 1.0;
}
public MyRectangle(double widthParam,double heightParam, String colorParam)
{
setWidth(widthParam);
setHeight(heightParam);
setColor(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 getWidth()*getHeight();
}
}
Explanation / Answer
please rate - thanks
you are missing the main program
class MyRectangle
{
private double width = 1.0;
private double height = 1.0;
private static String color ="white";
public MyRectangle()
{
width = 1.0;
height = 1.0;
}
public MyRectangle(double widthParam,double heightParam, String colorParam)
{
setWidth(widthParam);
setHeight(heightParam);
setColor(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 getWidth()*getHeight();
}
public static void main(String [] args){
MyRectangle r1 = new MyRectangle(1.5,2,"red");
MyRectangle r2 = new MyRectangle(3,5.5,"yellow");
print(r1,1);
print (r2,2);
}
public static void print(MyRectangle r, int n)
{System.out.println("Rectangle "+n);
System.out.println("height: "+r.getHeight());
System.out.println("width: "+r.getWidth());
System.out.println("color: "+r.getColor());
System.out.println("area: "+r.findArea()+" ");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.