请在课程中查看此问题的add方法。
如何根据用户输入的数量增加高度和宽度的输入。
public class Bounce
{
public static void main(String[]args)
{
//declare variables
Oblong myOblong = new Oblong();
double h = 0;
double w = 0;
Scanner keyboardIn = new Scanner(System.in);
System.out.print(" Enter the Height: ");
h = keyboardIn.nextInt();
System.out.print(" Enter the Width: ");
w = keyboardIn.nextInt();
myOblong.setHeight(h);
myOblong.setWidth(w);
System.out.println("Width: "+myOblong.getWidth());
System.out.println("Height: "+myOblong.getHeight());
System.out.print("Area: "+myOblong.calculateArea());
System.out.print("Add: "+myOblong.add());
public class Oblong
{
// instance variables
private double height;
private double width;
// constructor
public Oblong(){
height = 0.0;
width = 0.0;
}
// methods
public double getHeight()
{
return height;
}
public double getWidth()
{
return width;
}
public void setWidth(double w)
{
width = w;
}
public void setHeight(double h)
{
height = h;
}
public double calculateArea()
{
return width * height;
}
public void add(double w, double h)
{
height = height+h;
width = width+w;
}
}// end of class
上面的添加方法是我需要调用的方法,用于通过用户输入的值增加高度和宽度。
当我编译弹跳类时,它给了我一个错误的添加它说添加长方形不能应用于()。
不知道如何解决任何帮助会很棒。
谢谢,
标记