用户管理高级版
This commit is contained in:
parent
761fcb4905
commit
87f3d76415
4
src/chapter4/Example25.java
Normal file
4
src/chapter4/Example25.java
Normal file
@ -0,0 +1,4 @@
|
||||
package chapter4;
|
||||
|
||||
public class Examaple25 {
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
// 打印计算器菜单
|
||||
|
2
src/chapter4/example14/Example14.java
Normal file
2
src/chapter4/example14/Example14.java
Normal file
@ -0,0 +1,2 @@
|
||||
package chapter4.example14;public class Example14 {
|
||||
}
|
19
src/chapter4/object/Test.java
Normal file
19
src/chapter4/object/Test.java
Normal file
@ -0,0 +1,19 @@
|
||||
package chapter4.object;
|
||||
|
||||
class Student {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public Student(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Student {name=" + name + ", age=" + age + "}";
|
||||
}
|
||||
}
|
||||
|
||||
public class Test {
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user