第12章上機練習3 新
阿新 • • 發佈:2019-02-16
package cn.bdqn.com; import java.util.*; public class Menu { Scanner input = new Scanner(System.in); public void showMenu() { System.out.println("\t\t歡迎登陸我行我素購物系統\n"); System.out.println("\n\t\t1.登陸系統\t\t"); System.out.println("\t\t2.退出\t\t"); System.out .println("*************************************************************************************\n"); System.out.println("請輸入數字:"); /*int num = input.nextInt(); switch (num) { case 1: showmainMenu(); break; case 2: System.out.println("退出"); break; }*/ } public void showmainMenu() { boolean con; do {System.out.println("我行我素購物管理系統\t\n"); System.out .println("*************************************************************************************\n"); System.out.println("\t\t1.客戶資訊管\t\t\n"); System.out.println("\t\t2.真情回饋\t\t\n"); System.out .println("*************************************************************************************\n"); System.out.println("請輸入數字或按0返回上一級選單:"); con = false; int no = input.nextInt(); if (no == 1) { showcustoMenu(); } else if (no == 2) { showsendMenu(); } else if (no == 0) { showMenu(); } else { System.out.println("請輸入數字!"); con = true; } } while (con); } public void showcustoMenu() { System.out.println("我行我素購物管理系統\t\n"); System.out .println("*************************************************************************************\n"); System.out.println("\t\t1.顯示所有客戶資訊\t\t\n"); System.out.println("\t\t2.新增客戶資訊\t\t\n"); System.out.println("\t\t3.修改客戶資訊\t\t\n"); System.out.println("\t\t4.查詢客戶資訊\t\t\n"); System.out .println("*************************************************************************************\n"); System.out.println("請輸入數字或按0返回上一級選單:"); boolean con; do { con = false; int no = input.nextInt(); if (no == 1) { System.out.println("1.顯示所有客戶資訊"); } else if (no == 2) { System.out.println("2.新增客戶資訊"); } else if (no == 3) { System.out.println("3.修改客戶資訊"); } else if (no == 4) { System.out.println("4.查詢客戶資訊"); } else if (no == 0) { showmainMenu(); } else { System.out.println("請輸入數字!"); con = true; } } while (con); } public void showsendMenu() { System.out.println("我行我素購物管理系統\t\n"); System.out .println("*************************************************************************************\n"); System.out.println("\t\t1.幸運大放送\t\t\n"); System.out.println("\t\t2.幸運抽獎\t\t\n"); System.out.println("\t\t3.生日問候\t\t\n"); System.out .println("*************************************************************************************\n"); System.out.println("請輸入數字或按0返回上一級選單:"); boolean con; do { con = false; int no = input.nextInt(); if (no == 1) { System.out.println("1.幸運大放送"); } else if (no == 2) { System.out.println("2.幸運抽獎"); } else if (no == 3) { System.out.println("3.生日問候"); } else if (no == 0) { showmainMenu(); } else { System.out.println("請輸入數字!"); con = true; } } while (con); } } package cn.bdqn.com; import java.util.*; public class TestMenu { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); Menu v = new Menu(); boolean con; do { v.showMenu(); con = false; int no = input.nextInt(); switch (no) { case 1: v.showmainMenu(); con = true; break; case 2: System.out.println("謝謝您的使用!"); break; } } while (con); } }