- <span style="color:#000000;">package com.lxwl.ll;
- import java.util.Scanner;
- public class Atm {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("---------------------------------------------");
- System.out.println("----------------欢迎使用ATM取款机---------------");
- System.out.println("---------------@Author lengxuan----------------");
- System.out.println("---------------QQ:541473-----------------");
- double balance_value = 5000;
- int count = 0;
- // String user = "admin";//的账号
- String pwd = "123456";//初始的密码
- outer:while (true) {
- Scanner scanner = new Scanner(System.in);
- System.out.print("账号:");
- String userName =scanner.next();
- System.out.print("密码:");
- String password =scanner.next();
- if (userName.equals("admin") && password.equals(pwd)) {
- System.out.println("账号正确!");
- System.out.println("登陆成功");
- while (true) {
- System.out.println("---------------------------------------------");
- System.out.println("-------------请输入你想要的操作类型:---------------");
- System.out.println("-------------1.余额查询 2.取款---------------");
- System.out.println("-------------3.转账 4.存款---------------");
- System.out.println("-------------5.修改密码 6.退卡---------------");
- System.out.println("---------------------------------------------\n");
- int n1 = scanner.nextInt();
- switch (n1) {
- case 1:
- System.out.println("您的账户是:" + userName);
- System.out.println("剩余余额为:" + balance_value);
- System.out.println("--------------接下来您想做的操作是:--------------");
- System.out.println("--------------1.返回主界面 2.取卡---------------");
- int n2 = scanner.nextInt();
- switch (n2) {
- case 1:
- continue;
- case 2:
- System.exit(0);
- }
- // 您的余额是:5000.0
- break;
- case 2:
- System.out.println("请输入您要取钱的数量(元):");
- double outlay1 = scanner.nextDouble();//outlay支出
- balance_value = balance_value - outlay1;
- System.out.println("取钱成功!");
- System.out.println("---------------------------------------------");
- System.out.println("--------------接下来您想做的是: -----------------");
- System.out.println("--------------1.返回主界面 2.取卡---------------");
- System.out.println("---------------------------------------------");
- int n3 = scanner.nextInt();
- switch (n3) {
- case 1:
- continue;
- case 2:
- System.exit(0);
- }
- break;
- case 3:
- System.out.println("请输入您要转账的数量:");
- double outlay2 = scanner.nextDouble();//outlay2支出转账
- balance_value = balance_value - outlay2;
- System.out.println("转账成功!");
- System.out.println("---------------------------------------------");
- System.out.println("--------------接下来您想做的是: -----------------");
- System.out.println("--------------1.返回主界面 2.取卡---------------");
- System.out.println("---------------------------------------------");
- int n4 = scanner.nextInt();
- switch (n4) {
- case 1:
- continue;
- case 2:
- System.exit(0);
- }
- break;
- case 4:
- System.out.println("请输入您要存款的数量:");
- double income = scanner.nextDouble();//income收入存款
- balance_value = balance_value + income;
- System.out.println("存款成功!");
- System.out.println("---------------------------------------------");
- System.out.println("--------------接下来您想做的是: -----------------");
- System.out.println("--------------1.返回主界面 2.取卡---------------");
- System.out.println("---------------------------------------------");
- int n5 = scanner.nextInt();
- switch (n5) {
- case 1:
- continue;
- case 2:
- System.exit(0);
- }
- break;
- case 5:
- System.out.println("请输入新密码:");
- // String newPassword = scanner.next();
- pwd = scanner.next();
- System.out.println("修改成功,请重新登录:");
- break;
- case 6:
- System.exit(0);
- }
- break;
- }
- }else {
- count++;
- System.out.println("密码错误或账号不存在!" + " 您还有" + (3 - count) + "次输入机会!\n");
- if (count == 3) {
- System.out.println("------不好意思,您的卡被吞!嘿嘿嘿~------");
- System.exit(0);
- }
- }
- }
- }
- public static String manager(){
- return;
- }
- }</span><span style="font-family:SimSun;color:#ff0000;">
- </span>
Java编写ATM(单机)小程序
最新推荐文章于 2021-02-25 13:34:28 发布