Nhập student
public void input(Scanner scanner) {
id = exceptions.integerInput(scanner, "Please input id:");
System.out.println("Please input name:");
name = scanner.nextLine();
markMath = exceptions.doubleInput(scanner, "Please input mark Math:");
markPhysic = exceptions.doubleInput(scanner, "Please input mark Physic:");
markChemistry = exceptions.doubleInput(scanner, "Please input mark Chemistry:");
}
Nhập student vào list
public void inputStudents(Scanner scanner) {
do {
System.out.println("Do you want to enter Students:");
System.out.println("1.Input");
System.out.println("0.Exit");
int choose = exceptions.integerInput(scanner, "--------------");
if (choose == 0) {
break;
}
switch (choose) {
case 1:
Student student = new Student();
student.input(scanner);
if (list.isEmpty()) {
list.add(student);
break;
} else {
if (student instanceof List) {
System.out.println("This ID already exist, please re-enter another ID");
} else {
list.add(student);
break;
}
}
default:
System.out.println("Please choose 1 or 0");
break;
}
} while (true);
}
Mình muốn so sánh id vừa nhập có sẵn trong list không. Nếu có thì sẽ xuất thông báo.