面向对象思维:
自由切换菜单
import java.util.Scanner;
public class MyShopping {
public Scanner input;
public MyShopping(Scanner input) {
super();
this.input = input;
}
public void firstMenu() {
System.out.println("\t欢迎使用我行我素购物管理系统");
System.out.println("\t\t1.登录系统");
System.out.println("\t\t2.退出");
System.out.println("********************************");
System.out.print("请选择,请输入数字:");
switch(input.nextInt()){
case 1:
//登录系统
if(userpwd()){
login();
}else{
System.out.println("您没有权限进入系统,请重新输入");
firstMenu();
}
break;
case 2:
//退出
logout();
break;
default:
System.out.println("输入有误,请重新输入");
firstMenu();
break;
}
}
/**
* 退出
*/
public void logout(){
System.out.println("已退出系统!");
return;
}
/**
* 登录系统
*/
public void login(){
System.out.println("\t我行我素购物管理系统主菜单");
System.out.println("******************************");
System.out.println("\t\t1.客户信息管理");
System.out.println("\t\t2.真情回顾");
System.out.println("******************************");
System.out.println("请选择,输入数字或按0返回上一级菜单:");
switch(input.nextInt()){
case 1:
//1.客户信息管理
userInfo();
break;
case 2:
//2.真情回顾
zhengqing();
break;
case 0:
//返回上一级
firstMenu();
break;
default:
System.out.println("输入有误,请重新输入");
login();
break;
}
}
/**
* 1.客户信息管理
*/
public void userInfo(){
System.out.println("\t我行我素购物管理系统 -> 客户信息管理");
System.out.println("*******************************");
System.out.println("\t\t1.客户姓名");
System.out.println("\t\t2.客户年龄");
System.out.println("*******************************");
System.out.println("请输入0返回上一级");
switch(input.nextInt()){
case 0:
//返回上一级,第二级
login();
break;
default:
System.out.println("输入有误,请重新输入");
userInfo();
break;
}
}
/**
* 2.真情回顾
*/
public void zhengqing(){
System.out.println("\t我行我素购物管理系统 -> 真情回顾");
System.out.println("*******************************");
System.out.println("\t\t1幸运大放送");
System.out.println("\t\t2.幸运抽奖");
System.out.println("*******************************");
System.out.println("请输入0返回上一级");
switch(input.nextInt()){
case 0:
//返回上一级,第二级
login();
break;
default:
System.out.println("输入有误,请重新输入");
userInfo();
break;
}
}
/**
* 用户名和密码
* @param args
*/
public boolean userpwd(){
System.out.print("请输入用户名:");
String name = input.next();
System.out.print("请输入密码:");
String pwd = input.next();
return "Jade".equals(name) && "0000".equals(pwd);
}
public static void main(String[] args) {
MyShopping shop = new MyShopping(new Scanner(System.in));
shop.firstMenu();
}
}