学校人员信息管理系统代码
时间: 2023-07-23 20:56:33 浏览: 92
这是一个简单的学校人员信息管理系统的Java代码示例:
```java
import java.util;
import java.util.List;
import java.util.Scanner;
class Person {
private String name;
private int age;
private String role;
public Person(String name, int age, String role) {
this.name = name;
this.age = age;
this.role = role;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getRole() {
return role;
}
}
class SchoolManagementSystem {
private List<Person> personList;
public SchoolManagementSystem() {
personList = new ArrayList<>();
}
public void addPerson(Person person) {
personList.add(person);
}
public void displayPersons() {
for (Person person : personList) {
System.out.println("Name: " + person.getName());
System.out.println("Age: " + person.getAge());
System.out.println("Role: " + person.getRole());
System.out.println();
}
}
}
public class Main {
public static void main(String[] args) {
SchoolManagementSystem managementSystem = new SchoolManagementSystem();
Scanner scanner = new Scanner(System.in);
System.out.println("=== School Management System ===");
while (true) {
System.out.println("1. Add Person");
System.out.println("2. Display Persons");
System.out.println("3. Quit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
if (choice == 1) {
System.out.print("Enter name: ");
String name = scanner.next();
System.out.print("Enter age: ");
int age = scanner.nextInt();
System.out.print("Enter role: ");
String role = scanner.next();
Person person = new Person(name, age, role);
managementSystem.addPerson(person);
System.out.println("Person added successfully!");
} else if (choice == 2) {
managementSystem.displayPersons();
} else if (choice == 3) {
break;
} else {
System.out.println("Invalid choice! Please try again.");
}
System.out.println();
}
scanner.close();
}
}
```
这段代码实现了一个简单的学校人员信息管理系统,可以添加人员信息并显示已添加的人员信息。你可以根据自己的需求进行扩展和修改。
阅读全文