Java點(diǎn)名系統(tǒng)
public class Student { private String name; private String phoneNumber; public Student(String name, String phoneNumber) { this.name = name; this.phoneNumber = phoneNumber; } public String getName() { return name; } public String getPhoneNumber() { return phoneNumber; } public void setName(String name) { this.name = name; } public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } } public class RollCallSystem { private Liststudents; public RollCallSystem() { students = new ArrayList<>(); } public void addStudent(Student student) { students.add(student); } public void removeStudent(Student student) { students.remove(student); } public void printRollCallList() { System.out.println("點(diǎn)名列表如下:"); for (Student student : students) { System.out.println(student.getName() + "\t" + student.getPhoneNumber()); } } } public class Main { public static void main(String[] args) { RollCallSystem rollCallSystem = new RollCallSystem(); rollCallSystem.addStudent(new Student("張三", "123456789")); rollCallSystem.addStudent(new Student("李四", "987654321")); rollCallSystem.addStudent(new Student("王五", "111111111")); rollCallSystem.printRollCallList(); } }