Browse Source

上传文件至 ''

main
peisishuang 2 months ago
parent
commit
e5190123df
  1. 30
      基础题-Shape.txt
  2. 20
      挑战题—Person.txt
  3. 33
      进阶题-Vehicle.txt

30
基础题-Shape.txt

@ -0,0 +1,30 @@
基础题—Shape类
class Shape {
public void draw() {
System.out.println("绘制形状");
}
}
class Circle extends Shape {
@Override
public void draw() {
System.out.println("绘制圆形");
}
}
class Rectangle extends Shape {
@Override
public void draw() {
System.out.println("绘制矩形");
}
}
public class ShapeDemo {
public static void drawShape(Shape s) {
s.draw();
}
public static void main(String[] args) {
Shape circle = new Circle();
Shape rectangle = new Rectangle();
drawShape(circle);
drawShape(rectangle);
}
}

20
挑战题—Person.txt

@ -0,0 +1,20 @@
挑战题—Person
public class PersonManagerTest {
public static void main(String[] args) {
PersonManager manager = new PersonManager();
Student student1 = new Student("张三", 18, "S001", 95.5);
Student student2 = new Student("李四", 19, "S002", 88.0);
Teacher teacher1 = new Teacher("王老师", 35, "T001", "数学");
Teacher teacher2 = new Teacher("李老师", 40, "T002", "英语");
manager.addPerson(student1);
manager.addPerson(student2);
manager.addPerson(teacher1);
manager.addPerson(teacher2);
manager.displayAllPersons();
manager.processSpecificAttributes();
}
}

33
进阶题-Vehicle.txt

@ -0,0 +1,33 @@
进阶题——Vehicle
abstract class Vehicle {
public abstract void run();
}
class Car extends Vehicle {
@Override
public void run() {
System.out.println("汽车在公路上行驶");
}
}
class Bike extends Vehicle {
@Override
public void run() {
System.out.println("自行车在道路上骑行");
}
}
class Truck extends Vehicle {
@Override
public void run() {
System.out.println("卡车在高速公路上运输货物");
}
}
public class VehicleDemo {
public static void main(String[] args) {
Vehicle[] vehicles = new Vehicle[3];
vehicles[0] = new Car();
vehicles[1] = new Bike();
vehicles[2] = new Truck();
for (Vehicle vehicle : vehicles) {
vehicle.run();
}
}
}
Loading…
Cancel
Save