1.main()方法
public class test { public static void main(String[] args) { ArrayList<people> people = new ArrayList<>(); Scanner scanner = new Scanner(System.in); while (true) { System.out.println("1.注册" + "\t" + " 2.登录" + "\t" + " 3.退出" + "\t" + "4.超级管员查看"); System.out.println("------------------------------"); System.out.println("请选择菜单:"); int input = scanner.nextInt(); switch (input) { case (1): register(people); break; case (2): login(people); break; case (3): System.out.println("欢迎再次光临"); System.exit(0); break; case (4): System.out.println("超级管理员查看所有用户信息:"); look(people); break; } } } public static void register(ArrayList<people> a) { int sum = 0; people people1 = new people(); Scanner scanner = new Scanner(System.in); System.out.print("请输入用户名:"); String p1 = scanner.next(); System.out.print("请存钱数:"); double pp1 = scanner.nextInt(); System.out.print("请输入密码:"); String ppp1 = scanner.next(); people1.setName(p1); people1.setMoney(pp1); people1.setPassword(ppp1); a.add(people1); //a.add(people1); System.out.println("成功注册"); for (int i = 0; i < a.size(); i++) { System.out.println(a.get(i).getName()); } } public static void login(ArrayList<people> aa) { Scanner scanner = new Scanner(System.in); for (int bb = 0; bb < 3; bb++) { System.out.println("请输入用户名密码登录"); System.out.print("用户名:"); String a = scanner.next(); System.out.print("密码:"); String b = scanner.next(); for (int i = 0; i < aa.size(); i++) { if (a.equals(aa.get(i).getName()) && b.equals(aa.get(i).getPassword())) { System.out.println("欢迎进入赵一玄银行"); System.out.println("用户:" + a + "\t" + "存款:" + aa.get(i).getMoney()); System.out.println("please wo select:" + " \t " + "1:取钱"); int s = scanner.nextInt(); other: while (true) { if (s == 1) { Scanner sc = new Scanner(System.in); System.out.print("请输入取款数:"); int money = scanner.nextInt(); for (int j = 0; j < aa.size(); j++) { if (a.equals(aa.get(j).getName()) && money <= aa.get(j).getMoney()) { double mm = aa.get(j).getMoney(); mm -= money; aa.get(j).setMoney(mm); System.out.println("用户:" + aa.get(i).getName() + " \t存款数:" + aa.get(j).getMoney()); break other; } else { System.out.println("余额不足!"); } } } else { System.out.println("用户名或密码错误,请重新登录"); break; } } } else { if (i == 2) { System.out.println("机会用完"); } else { System.out.println("还剩" + (2 - i) + "次机会"); } } } } } public static void look(ArrayList<people> aa) { for (int l = 0; l < aa.size(); l++) { System.out.println("name:" + aa.get(l).getName() + " \t money:" + aa.get(l).getMoney()); } } }
2.people对象
public class people { String name; String password; String birthday; double money; public Double getMoney() { return money; } public void setMoney(Double money) { this.money = money; } public String getPassword() { return password; } public String getBirthday() { return birthday; } public void setBirthday(String birthday) { this.birthday = birthday; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } }标签:aa,String,登录,System,管理员,println,方法,public,out From: https://blog.csdn.net/weixin_63139716/article/details/140414259