public class MyRectangle {
public static void main(String[] args) {
/* 请定义一个描述矩形(MyRectangle)的类,包含宽和高两个属性,提供获取矩形
周长(perimeter)和面积(area)的方法。并编写测试类进行测试。*/
//矩形的宽为a
double a;
//矩形高为b
double b;
perimeter(2,5);
System.out.println(perimeter(2,5));
area(2,5);
System.out.println(area(2,5));
}
public static double perimeter(double a, double b) {
double perimeter = 2 * a + 2 * b;
return perimeter;
}
public static double area(double a, double b) {
double area = a * b;
return area;
}
} |
|