本文介绍了子菜单 - CMD中的Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。我想为我的应用程序创建一个菜单。但我有一个问题。
这是代码。
Hello everyone. I want to create a menu for my application. But I have a problem.
This is the code.
class MainMenu{
Scanner MainMenusc = new Scanner(System.in);
public int YourChoice;
public void MainMenu(){
System.out.println("Welcome");
System.out.println("1. Quan ly sinh vien");
System.out.println("2. Quan ly diem");
System.out.println("3. Quan ly thong ke");
System.out.println("");
System.out.println("0. Thoat");
System.out.print("Vui long chon chuc nang muon su dung: ");
YourChoice = MainMenusc.nextInt();
if(YourChoice==1){
Menu1 mn1 = new Menu1();
mn1.Menu1();
}
}
}
class Menu1 extends MainMenu{
Scanner Menu1sc = new Scanner(System.in);
public int YourChoice;
public void Menu1(){
System.out.println("Welcome");
System.out.println("1. Nhap sinh vien moi");
System.out.println("2. Sua thong tin sinh vien");
System.out.println("3. Xoa sinh vien");
System.out.println("");
System.out.println("9. Return to main menu");
System.out.println("0. Thoat");
System.out.print("Vui long chon chuc nang muon su dung: ");
YourChoice = Menu1sc.nextInt();
if(YourChoice==9){
MainMenu.MainMenu();
}
}
}
class Menu2 extends MainMenu{
Scanner Menu2sc = new Scanner(System.in);
public int YourChoice;
public void Menu2(){
System.out.println("Welcome");
System.out.println("1. Nhap diem");
System.out.println("2. Sua diem");
System.out.println("3. Xoa diem");
System.out.println("4. Sap xep diem");
System.out.println("");
System.out.println("9. Return to main menu");
System.out.println("0. Thoat");
System.out.print("Vui long chon chuc nang muon su dung: ");
YourChoice = Menu2sc.nextInt();
}
}
class Menu3 extends MainMenu{
Scanner Menu3sc = new Scanner(System.in);
public int YourChoice;
public void Menu3(){
System.out.println("Welcome");
System.out.println("1. Thong ke sinh vien");
System.out.println("2. Thong ke diem");
System.out.println("");
System.out.println("9. Return to main menu");
System.out.println("0. Thoat");
System.out.print("Vui long chon chuc nang muon su dung: ");
YourChoice = Menu3sc.nextInt();
}
}
class Menu31 extends Menu3{
Scanner Menu31sc = new Scanner(System.in);
public int YourChoice;
public void Menu31(){
System.out.println("Welcome");
System.out.println("1. Tong so sinh vien");
System.out.println("2. Tong so sinh vien toan");
System.out.println("3. Tong so sinh vien ly");
System.out.println("4. Tong so sinh vien hoa");
System.out.println("");
System.out.println("9. Ve menu truoc");
System.out.println("0. Thoat");
System.out.print("Vui long chon chuc nang muon su dung: ");
YourChoice = Menu31sc.nextInt();
}
}
class Menu32 extends Menu3{
Scanner Menu32sc = new Scanner(System.in);
public int YourChoice;
public void Menu32(){
System.out.println("Welcome");
System.out.println("1. So sinh vien gioi ");
System.out.println("2. So sinh vien kha");
System.out.println("3. So sinh vien trung binh");
System.out.println("4. So sinh vien yeu");
System.out.println("5. Sinh vien co diem cao nhat");
System.out.println("6. Sinh vien co diem thap nhat");
System.out.println("");
System.out.println("9. Ve menu truoc");
System.out.println("0. Thoat");
System.out.print("Vui long chon chuc nang muon su dung: ");
YourChoice = Menu32sc.nextInt();
}
}
//Class main
class MainTask{
public static void main(String args[]){
/* stm = new StudentManager();
stm.InputInfo();
stm.ViewInfo();*/
MainMenu menu = new MainMenu();
menu.MainMenu();
}
}
当我从Menu1,Menu2或Menu3切换回MainMenu时,如何拨打电话?返回MainMenu方法(通过我在main方法中创建的对象menu)而不创建新方法? (这意味着不使用new关键字,例如
When I switch back to MainMenu from Menu1, Menu2 or Menu3, how can I call back the MainMenu method (through the object "menu" that I created in main method) without create a new one? (it means not use the "new" keyword, something like
MainMenu mn = new Mainmenu
)?
非常感谢!
)?
Thank you very much!
推荐答案
这篇关于子菜单 - CMD中的Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!