在JAVA中显示迭代菜单
我在程序的主要功能中编写了以下代码,以生成菜单驱动程序。菜单上基本上有六个可用选项,在JAVA中显示迭代菜单,java,css,menu,Java,Css,Menu,我在程序的主要功能中编写了以下代码,以生成菜单驱动程序。菜单上基本上有六个可用选项,Menu()不仅显示菜单,还返回用户的选择。如果你需要密码,我会贴出来的 public static void main(String args[])throws IOException { BufferedReader bw=new BufferedReader(new InputStreamReader(System.in)); attendance_and_student_management
Menu()
不仅显示菜单,还返回用户的选择。如果你需要密码,我会贴出来的
public static void main(String args[])throws IOException
{ BufferedReader bw=new BufferedReader(new InputStreamReader(System.in));
attendance_and_student_management object=new attendance_and_student_management();
int flag=1;
while(flag==1)
{ int var=object.menu();
if(var==1)
{ System.out.println("\f");
object.add_student();
System.out.println();
System.out.println("Would you like to return to the Main Menu to perform more tasks? Press 1 for Yes and 0 for No");
flag=Integer.parseInt(bw.readLine());
}
else if(var==2)
{ System.out.println("\f");
object.search_student();
System.out.println();
System.out.println("Would you like to return to the Main Menu to perform more tasks? Press 1 for Yes and 0 for No");
flag=Integer.parseInt(bw.readLine());
}
else if(var==3)
{ System.out.println("\f");
object.change_student_information();
System.out.println();
System.out.println("Would you like to return to the Main Menu to perform more tasks? Press 1 for Yes and 0 for No");
flag=Integer.parseInt(bw.readLine());;
}
else if(var==4)
{ System.out.println("\f");
object.take_attendance();
System.out.println();
System.out.println("Would you like to return to the Main Menu to perform more tasks? Press 1 for Yes and 0 for No");
flag=Integer.parseInt(bw.readLine());;
}
else if(var==5)
{ System.out.println("\f");
object.attendance_summary();
System.out.println();
System.out.println("Would you like to return to the Main Menu to perform more tasks? Press 1 for Yes and 0 for No");
flag=Integer.parseInt(bw.readLine());;
}
else if(var==6)
{
System.out.println("\f");
object.monthly_defaulter_list();
System.out.println();
System.out.println("Would you like to return to the Main Menu to perform more tasks? Press 1 for Yes and 0 for No");
flag=Integer.parseInt(bw.readLine());;
}
else if(var==7)
{ System.out.println("\f");
System.out.println("THANK YOU FOR USING THE PROGRAM!!");
System.exit(0);
}
else
{ System.out.println("\f");
System.out.println();
System.out.println("Invalid Input. Would you like to try again? Press 1 for Yes");
int chhh=Integer.parseInt(bw.readLine());
if(chhh==1)
{ flag=1;
}
else
{ flag=0;
}
}
}
}
现在我只面临这段代码的一个问题,它指向一个特定的方法,并且永远停留在该方法上。例如,我想添加一个学生。在菜单上,我选择1,因为var==1是true,所以调用了add\u student方法。一旦我添加完一个学生,我就无法返回菜单。我的意思是这条线
System.out.println(“是否要返回主菜单以执行更多任务…”)代码>未执行。缺陷是什么
我的目标是首先通过菜单功能显示菜单,然后询问用户是否希望执行更多任务。如果他/她愿意,则按下“Y”键,菜单应再次显示,以此类推。如果在任何迭代之后,用户想要退出,那么他/她应该选择7作为退出选项,或者只需输入“N”或任何其他有效字符
PS:这是我对代码的新尝试,我决定更改switch语句,因为我不完全理解它。您有什么错误吗?您没有从默认部分中断。这种中断正在使您脱离循环,因此它会立即停止。我们需要知道出勤和学生管理
课程如何解决第一个问题。