我需要能够将矩形的长度和宽度输入到控制台并计算其周长和面积。除了接受我的输入以进行计算外,我还有其他工作。我知道我很接近,但似乎无法弄清楚。在此先感谢您的帮助。请记住,我是一个很好的新手,所以你的答案一开始可能对我没有意义。我无法得到它来计算我输入到控制台的值。
package .cnit325_lab1;
public class Rectangle {
private static double length;
private static double width;
public Rectangle() {
length=0.0;
width=0.0;
}
public Rectangle(double l, double w) {
length = l;
width = w;
}
public double FindArea() {
return length*width;
}
public double FindPerim() {
return length*2 + width*2;
}
}
package .cnit325_lab1;
import ;
public class TestRectangle {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanL = new Scanner ();
("Please enter the length of the rectangle: ");
double L = ();
Scanner scanW = new Scanner ();
("Please enter the length of the rectangle: ");
double W = ();
//int W = ();
double RectangleArea;
Rectangle unitRectangle = new Rectangle();
RectangleArea = ();
("The area of a unit rectangle is " + RectangleArea);
double RectanglePermiter;
Rectangle perimRectangle = new Rectangle();
RectanglePermiter = ();
("The permimiter of the unit rectangle is " + RectanglePermiter);
}
}