2021-01-26 java基础,类和对象实现超市购物管理系统

登录类

public class Manager1 {
	// 属性
	String name="aaa";
	String password="111";

	// 方法
	public String show() { // 返回管理员用户名
		return name;
	}
	public String pass() { // 返回管理员密码
		return password;
	}
}

菜单类

public class Menu {
	// 登录菜单
	public void nshowLoginMenu() {
		System.out.println("\t欢迎使用超市购物管理系统");
		System.out.println("* * * * * * * * * * * * * * * * * * * * *");
		System.out.println("\t\t1.登录系统\n");
		System.out.println("\t\t2.退出");
		System.out.println("* * * * * * * * * * * * * * * * * * * * *");
		System.out.println("请选择,输入数字:");
		// 判断用户输入
		boolean dui;
		dui = false;
		do {
			Scanner input = new Scanner(System.in);
			int sum = input.nextInt();
			if (sum == 1) {
				Manager1 a = new Manager1();
				System.out.print("请输入用户名:");
				String name = input.next();
				System.out.print("请输入密码:");
				String password = input.next();
				if (name.equals(a.name) && password.equals(a.password)) { // 输入正确进入系统
					a.name = name;
					a.password = password;
					nshowMainMenu();
				} else { // 输入错误,重新输入
					System.out.println("输入有误,请重新输入数字:");
					dui = true;
				}
			} else if (sum == 2) {
				System.out.println("退出系统,谢谢您的使用!");
			} else { // 输入错误,重新输入
				System.out.println("输入有误,请重新输入数字:");
				dui = true;
			}
		} while (dui);
	}

	// 主菜单
	public void nshowMainMenu() {
		System.out.println("\n\t超市购物管理系统主菜单");
		System.out.println("* * * * * * * * * * * * * * * * * * * * *");
		System.out.println("\t\t1.客户信息管理\n");
		System.out.println("\t\t2.真情回馈");
		System.out.println("* * * * * * * * * * * * * * * * * * * * *");
		System.out.println("请选择,输入数字或者按0返回上一级菜单:");
		// 判断用户输入
		boolean dui;
		do {
			dui = false;
			Scanner input = new Scanner(System.in);
			int num = input.nextInt();
			if (num == 1) {
				System.out.println("执行显示客户信息管理");
				nshowCustMenu();
			} else if (num == 2) {
				System.out.println("执行显示真情回馈");
				nshowSendGMenu();
			} else if (num == 0) { // 返回上级菜单
				nshowLoginMenu();
			} else { // 输入错误,重新输入
				System.out.println("输入有误,请重新输入数字:");
				dui = true;
			}
		} while (dui);
	}

	public void nshowCustMenu() {
		System.out.println("\n\t超市购物管理系统>客户信息管理");
		System.out.println("* * * * * * * * * * * * * * * * * * * * *");
		System.out.println("\t\t1.显示所有客户信息\n");
		System.out.println("\t\t2.添加客户信息\n");
		System.out.println("\t\t3.修改客户信息\n");
		System.out.println("\t\t4.查询客户信息");
		System.out.println("* * * * * * * * * * * * * * * * * * * * *");
		System.out.println("请选择,输入数字或者按0返回上一级菜单:");
		// 判断用户输入
		boolean dui;
		do {
			dui = false;
			Scanner input = new Scanner(System.in);
			int num = input.nextInt();
			if (num == 1) {
				System.out.println("执行显示所有客户信息");
			} else if (num == 2) {
				System.out.println("执行添加客户信息");
			} else if (num == 3) {
				System.out.println("执行修改客户信息");
			} else if (num == 4) {
				System.out.println("执行查询客户信息");
			} else if (num == 0) { // 返回上级菜单
				nshowMainMenu();
			} else { // 输入错误,重新输入
				System.out.println("输入有误,请重新输入数字:");
				dui = true;
			}
		} while (dui);
	}

	public void nshowSendGMenu() {
		System.out.println("\n\t超市购物管理系统>真情回馈");
		System.out.println("* * * * * * * * * * * * * * * * * * * * *");
		System.out.println("\t\t1.幸运大放送\n");
		System.out.println("\t\t2.幸运抽奖\n");
		System.out.println("\t\t3.生日问候");
		System.out.println("* * * * * * * * * * * * * * * * * * * * *");
		System.out.println("请选择,输入数字或者按0返回上一级菜单:");
		// 判断用户输入
		boolean dui;
		do {
			dui = false;
			Scanner input = new Scanner(System.in);
			int num = input.nextInt();
			if (num == 1) {
				System.out.println("执行幸运大放送");
			} else if (num == 2) {
				System.out.println("执行幸运抽奖");
			} else if (num == 3) {
				System.out.println("生日问候");
			} else if (num == 0) { // 返回上级菜单
				nshowMainMenu();
			} else { // 输入错误,重新输入
				System.out.println("输入有误,请重新输入数字:");
				dui = true;
			}
		} while (dui);
	}
}

测试类

public class TextMenu {

	public static void main(String[] args) {
		boolean dui=true;
		do {
		Menu s=new Menu();
		s.nshowLoginMenu();
		// 显示主菜单
		Scanner input=new Scanner(System.in);
		int sum=input.nextInt();
		switch(sum){
		case 1:
			s.nshowCustMenu();
			break;
		case 2:
			System.out.println("退出系统,感谢您的使用!");
			dui = true;
			break;
		}
		}while(dui);
	}

}

 

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值