1【问题描述】 定义一个 Retangle类,有长、宽等属性,定义构造方法用来初始化类的这些属性,定义方法输出Retangle的长宽和面积。编写应用程序使用Retangle。
【输入形式】
请输入长:
请输入宽:
【输出形式】
长是:
宽是:
面积是:
【输入样例】
Please input length: 4.0
Please input width: 3.0
【输出样例】
The lengh is:4.0
The width is:3.0
The area is:12.0
*
*/
import java.util.Scanner;
public class Retangle {
static double a, b, area;
public Retangle(double x, double y) {
a = x;
b = y;
area = 0;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.println("Please input length: ");
double a = in.nextDouble();
System.out.println("Please input width: ");
double b = in.nextDouble();
getlengtha(a);
getlengthb(b);
area();
}
public static void getlengtha(double x) {
a = x;
System.out.println("The lengh is:" + a);
}