import java.net.InetAddress; import java.net.UnknownHostException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; /** * @program: Demo * @description: 控制台模仿员工管理系统 菜单功能 1:查询用户 2:删除用户 3:冻结用户 4:解冻用户 5:用户退出 * @author: lsp * @create: 2019-11-13 09:30 * @version:1.0 **/ public class HomeWork { public static void main(String[] args) throws UnknownHostException { //创建三个数组,分别储存用户的姓名、年龄、和账号状态 String[] names = {"张三", "李四", "王五"}; int[] ages = {21, 22, 23}; String[] status = {"正常", "正常", "正常"}; //打印空格 for (int i = 0; i < 3; i++) { System.out.println(""); } System.out.println("------用户:" + InetAddress.getLocalHost().getHostName() + "登录成功------ 北京时间:" + new SimpleDateFormat("yyyy:MM:dd hh:mm:ss").format(new Date())); //打印空格 for (int i = 0; i < 3; i++) { System.out.println(""); } System.out.println("请选择要操作的步骤:"); System.out.println("1-->查询所有用户"); System.out.println("2-->查询某个用户"); System.out.println("3-->删除用户"); System.out.println("4-->冻结用户"); System.out.println("5-->解冻用户"); System.out.println("6-->用户退出"); Scanner scanner = new Scanner(System.in); Finish: while (true) { int num = 0; try { num = scanner.nextInt(); } catch (Exception a) { num = 0; scanner = new Scanner(System.in); } switch (num) { case 1: System.out.println("用户列表如下:"); for (int i = 0; i < names.length; i++) { if (names[i] != null) { System.out.println(" 用户名:" + names[i] + "---年龄:" + ages[i] + "---账号状态:" + status[i]); } } System.out.println("请选择要操作的步骤:"); System.out.println("1-->查询所有用户"); System.out.println("2-->查询某个用户"); System.out.println("3-->删除用户"); System.out.println("4-->冻结用户"); System.out.println("5-->解冻用户"); System.out.println("6-->用户退出"); break; case 2: System.out.println("请输入要查询的账号名"); Scanner scanner1 = new Scanner(System.in); int flag1 = 0; a: while (true) { String name = scanner1.next(); for (int i = 0; i < names.length; i++) { if (name.equals(names[i])) { flag1 = 1; System.out.println("用户名:" + names[i] + "---年龄:" + ages[i] + "---账号状态:" + status[i]); System.out.println("请选择要操作的步骤:"); System.out.println("1-->查询所有用户"); System.out.println("2-->查询某个用户"); System.out.println("3-->删除用户"); System.out.println("4-->冻结用户"); System.out.println("5-->解冻用户"); System.out.println("6-->用户退出"); break a; } } if (flag1 == 0) { System.out.println("您输入账号名不存在,请重新输入"); } } break; case 3: System.out.println("请输入要删除的账号名"); Scanner scanner2 = new Scanner(System.in); int flag3 = 0; b: while (true) { String name = scanner2.next(); for (int i = 0; i < names.length; i++) { if (name.equals(names[i])) { names[i] = null; System.out.println("删除成功"); System.out.println("请选择要操作的步骤:"); System.out.println("1-->查询所有用户"); System.out.println("2-->查询某个用户"); System.out.println("3-->删除用户"); System.out.println("4-->冻结用户"); System.out.println("5-->解冻用户"); System.out.println("6-->用户退出"); flag3 = 1; break b; } } if (flag3 == 0) { System.out.println("您输入账号名不存在,请重新输入"); } } break; case 4: System.out.println("请输入要冻结的账号名"); Scanner scanner3 = new Scanner(System.in); int flag4 = 0; c: while (true) { String name = scanner3.next(); for (int i = 0; i < names.length; i++) { if (name.equals(names[i])) { if (!status[i].equals("冻结中")) { status[i] = "冻结中"; System.out.println("冻结成功"); System.out.println("请选择要操作的步骤:"); System.out.println("1-->查询所有用户"); System.out.println("2-->查询某个用户"); System.out.println("3-->删除用户"); System.out.println("4-->冻结用户"); System.out.println("5-->解冻用户"); System.out.println("6-->用户退出"); flag4 = 1; break c; } else { System.out.println("改账号已经被冻结,无需再次冻结"); System.out.println("请选择要操作的步骤:"); System.out.println("1-->查询所有用户"); System.out.println("2-->查询某个用户"); System.out.println("3-->删除用户"); System.out.println("4-->冻结用户"); System.out.println("5-->解冻用户"); System.out.println("6-->用户退出"); break c; } } } if (flag4 == 0) { System.out.println("您输入账号名不存在,请重新输入"); } } break; case 5: System.out.println("请输入要解冻的账号名"); Scanner scanner4 = new Scanner(System.in); int flag5 = 0; d: while (true) { String name = scanner4.next(); for (int i = 0; i < names.length; i++) { if (name.equals(names[i])) { if (!status[i].equals("正常")) { status[i] = "正常"; System.out.println("解冻成功"); System.out.println("请选择要操作的步骤:"); System.out.println("1-->查询所有用户"); System.out.println("2-->查询某个用户"); System.out.println("3-->删除用户"); System.out.println("4-->冻结用户"); System.out.println("5-->解冻用户"); System.out.println("6-->用户退出"); flag5 = 1; break d; } else { System.out.println("改账号未被冻结,无需解冻"); System.out.println("请选择要操作的步骤:"); System.out.println("1-->查询所有用户"); System.out.println("2-->查询某个用户"); System.out.println("3-->删除用户"); System.out.println("4-->冻结用户"); System.out.println("5-->解冻用户"); System.out.println("6-->用户退出"); break d; } } } if (flag5 == 0) { System.out.println("您输入账号名不存在,请重新输入"); } } break; case 6: System.out.println("------用户:" + InetAddress.getLocalHost().getHostName() + "退出成功------ 北京时间:" + new SimpleDateFormat("yyyy:MM:dd hh:mm:ss").format(new Date())); break Finish; default: System.out.println("您所有入的操作编号不正确或者无效,请重新输入数字编号,例如(1、2、3、4、5、6)"); break; } } } }
控制台输出模拟用户管理系统
最新推荐文章于 2022-08-06 21:53:12 发布