用户管理高级版
This commit is contained in:
@@ -16,7 +16,8 @@ public class Main {
|
||||
case 1: // 圆形
|
||||
System.out.print("请输入圆形的半径:");
|
||||
double radius = sc.nextDouble();
|
||||
Shape circle = new Circle(radius);
|
||||
Circle circle = new Circle(radius);
|
||||
// Shape circle = new Circle(radius);
|
||||
ShapeCalculate.printArea(circle);
|
||||
ShapeCalculate.printPerimeter(circle);
|
||||
break;
|
||||
@@ -24,7 +25,8 @@ public class Main {
|
||||
System.out.print("请输入长方形的长和宽:");
|
||||
double length = sc.nextDouble();
|
||||
double width = sc.nextDouble();
|
||||
Shape rectangle = new Rectangle(length, width);
|
||||
// Shape rectangle = new Rectangle(length, width);
|
||||
Rectangle rectangle = new Rectangle(length, width);
|
||||
ShapeCalculate.printArea(rectangle);
|
||||
ShapeCalculate.printPerimeter(rectangle);
|
||||
break;
|
||||
|
||||
@@ -13,12 +13,33 @@ public final class ShapeCalculate {
|
||||
|
||||
// 打印图形面积
|
||||
public static void printArea(Shape shape) {
|
||||
System.out.println("面积:"+shape.getArea());
|
||||
if (shape instanceof Rectangle) {
|
||||
System.out.println("正方形面积:"+shape.getArea());
|
||||
} else if (shape instanceof Circle) {
|
||||
System.out.println("圆形面积:"+shape.getArea());
|
||||
} else {
|
||||
System.out.println("未知图形面积:" + shape.getArea());
|
||||
}
|
||||
}
|
||||
|
||||
// 打印图形周长
|
||||
public static void printPerimeter(Shape shape) {
|
||||
System.out.println("周长:"+shape.getPerimeter());
|
||||
// public static void printPerimeter(Shape shape) {
|
||||
// if (shape instanceof Rectangle) {
|
||||
// System.out.print("长方形");
|
||||
// } else if (shape instanceof Circle) {
|
||||
// System.out.print("圆形");
|
||||
// } else {
|
||||
// System.out.print("未知图形");
|
||||
// }
|
||||
// System.out.println("周长:"+shape.getPerimeter());
|
||||
// }
|
||||
|
||||
public static void printPerimeter(Circle circle) {
|
||||
System.out.println("圆形周长:"+circle.getPerimeter());
|
||||
}
|
||||
|
||||
public static void printPerimeter(Rectangle rectangle) {
|
||||
System.out.println("长方形周长:"+rectangle.getPerimeter());
|
||||
}
|
||||
|
||||
// 打印计算器菜单
|
||||
|
||||
Reference in New Issue
Block a user