Java编写ATM(单机)小程序

  1. <span style="color:#000000;">package com.lxwl.ll;  
  2.   
  3. import java.util.Scanner;  
  4.   
  5. public class Atm {  
  6.   
  7.     public static void main(String[] args) {  
  8.         // TODO Auto-generated method stub  
  9.         System.out.println("---------------------------------------------");  
  10.         System.out.println("----------------欢迎使用ATM取款机---------------");  
  11.         System.out.println("---------------@Author lengxuan----------------");  
  12.         System.out.println("---------------QQ:541473-----------------");  
  13.           
  14.         double balance_value = 5000;  
  15.         int count = 0;  
  16. //      String user = "admin";//的账号  
  17.         String pwd = "123456";//初始的密码  
  18.         outer:while (true) {  
  19.             Scanner scanner = new Scanner(System.in);  
  20.             System.out.print("账号:");  
  21.             String userName =scanner.next();  
  22.             System.out.print("密码:");  
  23.             String password =scanner.next();  
  24.   
  25.               
  26.             if (userName.equals("admin") && password.equals(pwd)) {  
  27.                 System.out.println("账号正确!");  
  28.                 System.out.println("登陆成功");  
  29.                 while (true) {  
  30.                     System.out.println("---------------------------------------------");  
  31.                     System.out.println("-------------请输入你想要的操作类型:---------------");  
  32.                     System.out.println("-------------1.余额查询          2.取款---------------");  
  33.                     System.out.println("-------------3.转账                 4.存款---------------");  
  34.                     System.out.println("-------------5.修改密码          6.退卡---------------");  
  35.                     System.out.println("---------------------------------------------\n");  
  36.   
  37.                     int n1 = scanner.nextInt();  
  38.                     switch (n1) {  
  39.                     case 1:  
  40.                         System.out.println("您的账户是:" + userName);  
  41.                         System.out.println("剩余余额为:" + balance_value);  
  42.                         System.out.println("--------------接下来您想做的操作是:--------------");  
  43.                         System.out.println("--------------1.返回主界面   2.取卡---------------");  
  44.                         int n2 = scanner.nextInt();  
  45.                         switch (n2) {  
  46.                         case 1:  
  47.                             continue;  
  48.                         case 2:  
  49.                             System.exit(0);  
  50.                         }  
  51.                         //                      您的余额是:5000.0  
  52.                         break;  
  53.                     case 2:  
  54.                         System.out.println("请输入您要取钱的数量(元):");  
  55.                         double outlay1 = scanner.nextDouble();//outlay支出  
  56.                         balance_value = balance_value - outlay1;  
  57.                         System.out.println("取钱成功!");  
  58.                         System.out.println("---------------------------------------------");  
  59.                         System.out.println("--------------接下来您想做的是: -----------------");  
  60.                         System.out.println("--------------1.返回主界面     2.取卡---------------");  
  61.                         System.out.println("---------------------------------------------");  
  62.                         int n3 = scanner.nextInt();  
  63.                         switch (n3) {  
  64.                         case 1:  
  65.                             continue;  
  66.                         case 2:  
  67.                             System.exit(0);  
  68.                         }  
  69.                         break;  
  70.                     case 3:  
  71.                         System.out.println("请输入您要转账的数量:");  
  72.                         double outlay2 = scanner.nextDouble();//outlay2支出转账  
  73.                         balance_value = balance_value - outlay2;  
  74.                         System.out.println("转账成功!");  
  75.                         System.out.println("---------------------------------------------");  
  76.                         System.out.println("--------------接下来您想做的是: -----------------");  
  77.                         System.out.println("--------------1.返回主界面     2.取卡---------------");  
  78.                         System.out.println("---------------------------------------------");  
  79.                         int n4 = scanner.nextInt();  
  80.                         switch (n4) {  
  81.                         case 1:  
  82.                             continue;  
  83.                         case 2:  
  84.                             System.exit(0);  
  85.                         }  
  86.                         break;  
  87.                     case 4:  
  88.                         System.out.println("请输入您要存款的数量:");  
  89.                         double income = scanner.nextDouble();//income收入存款  
  90.                         balance_value = balance_value + income;  
  91.                         System.out.println("存款成功!");  
  92.                         System.out.println("---------------------------------------------");  
  93.                         System.out.println("--------------接下来您想做的是: -----------------");  
  94.                         System.out.println("--------------1.返回主界面     2.取卡---------------");  
  95.                         System.out.println("---------------------------------------------");  
  96.                         int n5 = scanner.nextInt();  
  97.                         switch (n5) {  
  98.                         case 1:  
  99.                             continue;  
  100.                         case 2:  
  101.                             System.exit(0);  
  102.                         }  
  103.                         break;  
  104.                     case 5:  
  105.                         System.out.println("请输入新密码:");  
  106. //                      String newPassword = scanner.next();  
  107.                         pwd = scanner.next();  
  108.                         System.out.println("修改成功,请重新登录:");  
  109.                           
  110.                         break;  
  111.                     case 6:  
  112.                         System.exit(0);  
  113.                     }  
  114.                     break;  
  115.                 }  
  116.             }else {  
  117.                     count++;  
  118.                     System.out.println("密码错误或账号不存在!" + " 您还有" + (3 - count) + "次输入机会!\n");  
  119.                     if (count == 3) {  
  120.                         System.out.println("------不好意思,您的卡被吞!嘿嘿嘿~------");  
  121.                         System.exit(0);  
  122.                     }  
  123.                 }  
  124.         }  
  125.     }  
  126.     public static String manager(){  
  127.         return;  
  128.     }  
  129.       
  130. }</span><span style="font-family:SimSun;color:#ff0000;">  
  131. </span>
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值