import java.util.ArrayList;
import java.util.Scanner;
public class StudentList {
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<Student>();
int choice;
printMenu();
do {
Scanner input = new Scanner(System.in);
choice = input.nextInt();
switch (choice) {
case 1:
System.out.println("\nAdd a student\n");
students.add(addStudent());
printMenu();
break;
case 2:
System.out.println("\nFind a student\n");
findStudent(students);
printMenu();
break;
case 3:
System.out.println("\nDelete a student\n");
displayAllStudents(students);
printMenu();
break;
case 4:
System.out.println("\nDispay all students\n");
displayAllStudents(students);
printMenu();
break;
case 5:
System.out.println("\nDisplay the total number of students\n");
studentSize(students);
printMenu();
break;
case 6:
System.out.println("\nGoodbye!\n");
break;
default:
System.out
.println("\nYour choice," + choice + ", is invalid\n");
break;
}
} while (choice != 6);
}
public static void printMenu() {
System.out
.println("\nPlease select from the following menu:\n"
+ "\t1. Add a student\n" + "\t2. Find a student\n"
+ "\t3. Delete a student\n"
+ "\t4. Display all students\n"
+ "\t5. Display the total number of students\n"
+ "\t6. Exit\n");
System.out.print("Your choice: ");
}
public static Student addStudent() {
Scanner inputS = new Scanner(System.in);
System.out.println("First Name:");
String fName = inputS.nextLine();
System.out.println("Last Name:");
String lName = inputS.nextLine();
System.out.println("Major Name:");
String major = inputS.nextLine();
System.out.println("Student Name:");
Integer sNumber = inputS.nextInt();
System.out.println("gpa:");
double grade = inputS.nextDouble();
return new Student(fName, lName, Major, sNumber, grade);
}
public static void displayAllStudents(ArrayList<Student> students) {
for (Student s : students) {
System.out.print(s.toString());
}
}
public static void findStudent(ArrayList<Student> students) {
Scanner inputN = new Scanner(System.in);
String name = inputN.nextLine();
for (Student s : students) {
if (s.getFName().equals(name)) {
System.out.println(s);
break;
}
}
}
public static void deleteStudent(ArrayList<Student> students) {
Scanner inputS = new Scanner(System.in);
String sNum = inputS.next();
for (Student s : students) {
if (s.FName().equals(sNum)) {
students.remove(s);
break;
}
}
}
public static void studentSize(ArrayList<Student> students) {
System.out.printf("Size: %\n", students.size());
}
}
我无法弄清楚我的代码有什么问题
当我尝试编译时,它在这三件事上给了我一个错误
return new Student(fName, lName, Major, sNumber, grade);
if(s.FName().equals(sNum))
if(s.getFName().equals(name))