【发布时间】:2016-06-17 00:28:05
【问题描述】:
我正在使用 java AIDE 应用程序,并被要求完成我的问题中所述的任务。
每次我运行我的代码时,应用都会告诉我“程序应该在缩放后打印矩形区域。”
我不确定我做错了什么,请参阅下面的代码: ....p.s 我仍然不能 100% 确定缩放意味着什么,如果有人能解释一下,我将不胜感激。谢谢
public class Main
{
public static void main(String[] args)
{
Rectangle rect = new Rectangle(100, 200);
System.out.println(rect.getWidth());
System.out.println(rect.getHeight());
rect.setWidth(10);
rect.setHeight(20);
rect.scale(10);
System.out.println(rect.getArea());
}
}
class Rectangle
{
int width;
int height;
int factor;
Rectangle(int width, int height)
{
this.width = width;
this.height = height;
}
void setHeight(int height)
{
this.height = height;
}
void setWidth(int width)
{
this.width = width;
}
int getWidth()
{
return this.width;
}
int getHeight()
{
return this.height;
}
void scale(int factor)
{
width = width * factor;
height = height * factor;
}
int getArea()
{
return this.width * this.height;
}
【问题讨论】: