public void sortListByMark(Scanner scanner) {
System.out.println("1.Sort Student by Mark Math");
System.out.println("2.Sort Student by Mark Physic");
System.out.println("3.Sort Student by Mark Chemistry");
System.out.println("4.Sort Student by Mark Avg");
System.out.println("0.Exit");
boolean errorAll = true;
while (errorAll) {
int choose = Exceptions.integerInput(scanner, "----------------");
switch (choose) {
case 1:
Collections.sort(list, (a, b) -> (int) (a.getMarkMath() - b.getMarkMath()));
outputStudents();
System.out.println("---------------------------");
yesNo("Do you want sort again?");
boolean error = true;
while (error) {
choose = Exceptions.integerInput(scanner, "-----------------");
switch (choose) {
case 1:
error = false;
sortListByMark(scanner);
break;
case 2:
error = false;
errorAll = false;
break;
default:
System.out.println("Please enter 1 or 2");
break;
}
}
break;
case 2:
Collections.sort(list, (a, b) -> (int) (a.getMarkPhysic() - b.getMarkPhysic()));
outputStudents();
System.out.println("---------------------------");
yesNo("Do you want sort again?");
error = true;
while (error) {
choose = Exceptions.integerInput(scanner, "-----------------");
switch (choose) {
case 1:
error = false;
sortListByMark(scanner);
break;
case 2:
error = false;
errorAll = false;
break;
default:
System.out.println("Please enter 1 or 2");
break;
}
}
break;
case 3:
Collections.sort(list, (a, b) -> (int) (a.getMarkChemistry() - b.getMarkChemistry()));
outputStudents();
System.out.println("---------------------------");
yesNo("Do you want sort again?");
error = true;
while (error) {
choose = Exceptions.integerInput(scanner, "-----------------");
switch (choose) {
case 1:
error = false;
sortListByMark(scanner);
break;
case 2:
error = false;
errorAll = false;
break;
default:
System.out.println("Please enter 1 or 2");
break;
}
}
break;
case 4:
Collections.sort(list, (a, b) -> (int) (a.getMarkAVG() - b.getMarkAVG()));
outputStudents();
System.out.println("---------------------------");
yesNo("Do you want sort again?");
error = true;
while (error) {
choose = Exceptions.integerInput(scanner, "-----------------");
switch (choose) {
case 1:
error = false;
sortListByMark(scanner);
break;
case 2:
error = false;
errorAll = false;
break;
default:
System.out.println("Please enter 1 or 2");
break;
}
}
break;
case 0:
errorAll = false;
break;
default:
System.out.println("Please input the correct function in the menu");
break;
}
}
}
Khi mình đệ quy 5 lần thì phải thoát 5 lần mới về menu chính. Mình muốn khi đệ quy 5 lần và chỉ cần thoát 1 lần là về menu chính phải làm sao?