用Java写一个家教系统项目的代码
```
import java.util.*;
public class TutorSystem {
public static void main(String[] args) {
// Create an ArrayList of Tutors
ArrayList<Tutor> tutors = new ArrayList<Tutor>();
// Create a map to store tutor information by subject
Map<String, ArrayList<Tutor>> tutorMap = new HashMap<String, ArrayList<Tutor>>();
// Create a map to store student information by zip code
Map<String, ArrayList<Student>> studentMap = new HashMap<String, ArrayList<Student>>();
// Create a set to store the subjects that a tutor can teach
Set<String> subjects = new HashSet<String>();
// Populate the tutor, subject and student maps
populateTutors(tutors, tutorMap, subjects);
populateStudents(studentMap);
// Welcome user and prompt for action
System.out.println("Welcome to the tutor system! What would you like to do? Type 'help' for a list of options.");
Scanner scanner = new Scanner(System.in);
中文写代码软件 String input = Line();
while (!input.equals("quit")) {
// Process action
processCommand(input, tutors, tutorMap, studentMap, subjects, scanner);
// Ask for next command
System.out.println("What would you like to do now?");
input = Line();
}
System.out.println("Thank you for using the tutor system. Goodbye!");
}
// Method to populate tutor information in the tutor and subject maps
public static void populateTutors(ArrayList<Tutor> tutors, Map<String, ArrayList<Tutor>> tutorMap, Set<String> subjects) {
// Read in tutor information from file
// ....
// Populate tutor and subject maps
for (Tutor tutor : tutors) {
// Store tutor in tutor map
if (ainsKey(tutor.subject)) {
(tutor.subject).add(tutor);
} else {
ArrayList<Tutor> tutorList = new ArrayList<Tutor>();
tutorList.add(tutor);
tutorMap.put(tutor.subject, tutorList);
}
// Store subject in subjects set
subjects.add(tutor.subject);
}
}
// Method to populate student information in the student map
public static void populateStudents(Map<String, ArrayList<Student>> studentMap) {
// Read in student information from file
// ...
// Populate student map
for (Student student : students) {
// Store student in student map
if (ainsKey(student.zipCode)) {
(student.zipCode).add(student);
} else {
ArrayList<Student> studentList = new ArrayList<Student>();
studentList.add(student);
studentMap.put(student.zipCode, studentList);
}
}
}
// Method to process a command
public static void processCommand(String input, ArrayList<Tutor> tutors, Map<String, ArrayList<Tutor>> tutorMap, Map<String, ArrayList<Student>> studentMap, Set<String> subjects, Scanner scanner) {
if (input.equals("help")) {
printHelp();
} else if (input.equals("list tutors")) {
listTutors(tutors);
} else if (input.equals("list students")) {
listStudents(studentMap);
} else if (input.equals("find tutor")) {
findTutor(tutorMap, scanner);
} else if (input.equals("add tutor")) {
addTutor(tutors, tutorMap, subjects, scanner);
} else {
System.out.println("Invalid command. Type 'help' for a list of commands.");
}
}
// Method to print out a list of available tutor subjects
public static void printHelp() {
System.out.println("List of commands:");
System.out.println("- list tutors: list all the available tutors");
System.out.println("- list students: list all the students looking for tutors");
System.out.println("- find tutor: search for a tutor by subject");
System.out.println("- add tutor: add a new tutor to the system");
System.out.println("- quit: exit the tutor system");
}
// Method to print out a list of tutors
public static void listTutors(ArrayList<Tutor> tutors) {
System.out.println("Available tutors:");
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论