Может кто-нибудь помочь мне определить, где проблема? Какие бы опции я ни выбрал в конце меню уровня Курс / Студент / Год, программа всегда возвращается к циклу Годовой уровень.
Извините за грязную программу, я все еще новичок. Если у вас есть время, пожалуйста,помогите мне исправить мои коды.
Я должен делать это на каждом курсе в нашей школе, так что это будет слишком долго.
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char crs = 'C';
char yrr = 'Y';
char Std = 'S';
char inv = 'Y';
int yrlvl, sections, students;
ArrayList < String > yearlvl = new ArrayList < String > ();
yearlvl.add("First Year");
yearlvl.add("Second Year");
yearlvl.add("Third Year");
yearlvl.add("Fourth Year");
yearlvl.add("Fifth Year");
ArrayList < String > Sections = new ArrayList < String > ();
String[] alphabet = {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z"
};
ArrayList < String > SectionsName = new ArrayList < String > ();
ArrayList < String > Students = new ArrayList < String > ();
ArrayList < String > StudentsName = new ArrayList < String > ();
while ((crs == 'C' || crs == 'c')) {
System.out.println("========================================================================================");
System.out.println("\nPamantasan ng Lungsod ng Marikina\n");
System.out.println("Please choose a Course\n");
System.out.println("Professional Programs \nA.Bachelor in Elementary Education (BEEd");
System.out.println("\nEnter your letter of your choice:");
char course = input.next().charAt(0);
switch (course) {
case 'A':
case 'a':
System.out.println("\nWelcome to College of Bachelor in Elementary Education!\nDo you want to get major in Special education? (Y for yes)");
char se = input.next().charAt(0);
if ((se == 'y' || se == 'Y')) {
System.out.println("\nYou've chosen to get the major in Special Education!");
while ((yrr == 'Y' || yrr == 'y')) {
System.out.println("\nChoose the year level you want to create new section:\n1.First Year\n2.Second Year\n3.Third Year\n4.Fourth Year\n5.Fifth Year\nEnter the number of your choice:");
yrlvl = input.nextInt();
while ((Std == 'S' || Std == 's')) {
System.out.println("\nHow many Section you want to create for " + yearlvl.get(yrlvl - 1) + "? \nEnter 0 if none");
sections = input.nextInt();
for (int i = 1; i <= sections; i++) {
String xx;
System.out.print("\nSection #" + i + "\nEnter The Section Name No Spaces: ");
xx = input.next();
SectionsName.add(xx);
} //for for (sections-i)
System.out.println("\nThe following are section/s for " + yearlvl.get(yrlvl - 1) + ".");
for (int i = 0; i < SectionsName.size(); i++) {
System.out.println(alphabet[i] + "." + SectionsName.get(i));
} //for section names display
System.out.println("\nDo you want to add students or view students? ADD or DISPLAY:\nA. Add\n\nEnter your choice");
char choice = input.next().charAt(0);
if (choice == 'A' || choice == 'a') {
System.out.println("\nThe list of sections");
for (int i = 0; i < SectionsName.size(); i++) {
System.out.println((i + 1) + "." + SectionsName.get(i));
}
System.out.println("\nEnter the number of section in which you want to insert students");
int i = input.nextInt();
System.out.println("\nYou've chosen " + SectionsName.get(i - 1));
System.out.println("\nEnter the number of students you want in " + SectionsName.get(i - 1) + "\nEnter 0 if none");
int q = input.nextInt();
ArrayList < String > StudNum = new ArrayList < String > (q);
input.nextLine();
for (int w = 0; w < q; w++) {
System.out.println("Student #" + (w + 1) + " Name: ");
String xxx = input.nextLine();
StudNum.add(xxx);
} //StudNum
inv = 'Y';
while (inv == 'Y') {
System.out.println("\nReturn to A.Section Menu | B.Year Level Menu | C.Course Menu | D.Exit\nEnter the letter of your choice:");
//PROBLEM: When I Input letter B, I'm hoping it would go to Year level But it's going directly to Section Menu Same with Letter C
char chs = input.next().charAt(0);
switch (chs) {
case 'a':
case 'A':
crs = 'x';
yrr = 'x';
Std = 's';
Std = 'S';
inv = 'x';
break;
case 'b':
case 'B':
crs = 'x';
yrr = 'y';
yrr = 'Y';
Std = 's';
inv = 'x';
break;
case 'c':
case 'C':
crs = 'c';
crs = 'C';
yrr = 'y';
Std = 's';
inv = 'x';
break;
case 'd':
case 'D':
System.exit(0);
default:
System.out.println("Invalid Choice");
crs = 'c';
yrr = 'y';
Std = 'S';
break;
} //for switch(Chs)
} //while(inv)
} //for while (Std)
} //for while (yrr)
} //if (choiceA)
} //for if (se)
} // For while (crs)
} // For Switch (course)
}
}