You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
897 B
30 lines
897 B
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class SchoolSystem {
|
|
private List<Person> personList = new ArrayList<>();
|
|
|
|
// 统一的 addPerson 方法,替代原来的 addStudent / addTeacher
|
|
public void addPerson(Person p) {
|
|
personList.add(p);
|
|
System.out.println("Added: " + p);
|
|
}
|
|
|
|
public void listAll() {
|
|
System.out.println("\n--- All Members ---");
|
|
for (Person p : personList) {
|
|
System.out.println(p);
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
SchoolSystem system = new SchoolSystem();
|
|
|
|
system.addPerson(new Student("Alice", 20, "S001", 3.8));
|
|
system.addPerson(new Student("Bob", 19, "S002", 3.5));
|
|
system.addPerson(new Teacher("Mr. Chen", 35, "Math", 10));
|
|
system.addPerson(new Teacher("Ms. Li", 28, "English", 4));
|
|
|
|
system.listAll();
|
|
}
|
|
}
|
|
|