JAVA基础第六天

单用户ATM模拟程序:

import javax.swing.JOptionPane;

public class ATM {

public static int money =8000;       //银行卡里面现有的金额为8000
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临,工商银行");
boolean land = denglu();{
if(land==false){
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
}
while(true){
String s =JOptionPane.showInputDialog(null,"1、存款"+"\n"+"2、取款"+"\n"+"3、查询余额"+"\n"+"4、取卡");
int item =Integer.parseInt(s);
switch (item) {
case 1:
cunkuan();
break;
case 2:
qukuan();
break;
case 3:
cxye();
break;
case 4:
JOptionPane.showMessageDialog(null, "谢谢使用");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "非法输入,请输入1-4");
break;
}
}
             
}
/*
* 登陆框
* 登陆是否成功
* */
public static boolean denglu(){
for(int i=0;i<3;i++){
String card =JOptionPane.showInputDialog(null,"请输入卡号");
String psw = JOptionPane.showInputDialog(null,"请输入密码");
if(card.equals("123456")&& psw.equals("aaaaaa")){
    return true;
}
}
return false;
}
    /*
     * 查询余额
     * */
         public static void cxye(){
         
        JOptionPane.showMessageDialog(null, "账号余额:"+money);
         }
         /*
          * 存款
          * */
         public static void cunkuan(){
        String x = JOptionPane.showInputDialog(null,"请输入存入的金额:");
        int m = Integer.parseInt(x);
        money = money+m;
        String str =JOptionPane.showInputDialog(null, "是否显示余额? y/n");
        if(str.equals("y")){
        cxye();
        }
         
         }
         /*
          * 取款
          * */
         public static void qukuan(){
        String y =JOptionPane.showInputDialog(null,"请输入取款金额");
        int s =Integer.parseInt(y);
      
          if(money<s){
          JOptionPane.showMessageDialog(null, "余额不足,请重新输入");
          }
        else{
     
        money =money -s;
       
        String str =JOptionPane.showInputDialog(null, "是否显示余额?y/n");
        if(str.equals("y")){
        cxye();
        }
        }
         }
         }

2、多用户ATM机模拟程序:

import javax.swing.JOptionPane;

public class DyhATM {
public static String[] code ={"123456","21323","23256","12313"};
public static String[] pwd ={"aaa","bbb","ccc","ddd"};
public static int[] money={5000,6000,4000,2000};
//记录用户登陆系统的下标
public static int c=-1;
public static void main(String[] aaa){
  
JOptionPane.showMessageDialog(null, "欢迎光临,工商银行");

denglu();
if(c==-1){
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);

}
while(true){
String s =JOptionPane.showInputDialog(null,"1、存款"+"\n"+"2、取款"+"\n"+"3、查询余额"+"\n"+"4、取卡");
int item =Integer.parseInt(s);
switch (item) {
case 1:
cunkuan();
break;
case 2:
qukuan();
break;
case 3:
cxye();
break;
case 4:
JOptionPane.showMessageDialog(null, "谢谢使用");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "非法输入,请输入1-4");
break;
}
}
            
}
   
        //登陆界面

     public static void denglu(){
     for(int i=0;i<3;i++){
     String a =JOptionPane.showInputDialog(null,"请输入卡号");  
     String b =  JOptionPane.showInputDialog(null,"请输入密码");
     for(int x=0;x<code.length;x++){
     if(a.equals(code[x]) && b.equals(pwd[x])){
     c=x;
     return;
     }
     }
     
     } 
     }
       //查询界面
       public static void cxye(){
       
      JOptionPane.showMessageDialog(null, "账号余额:"+money[c]);
       }
       //存款界面
       public static void cunkuan(){
       String x = JOptionPane.showInputDialog(null,"请输入存入的金额:");
         int m = Integer.parseInt(x);
  money[c] = money[c]+m;
  String str =JOptionPane.showInputDialog(null, "是否显示余额? y/n");
  if(str.equals("y")){
  cxye();
  }
   
   }
       public static void qukuan(){
      String y =JOptionPane.showInputDialog(null,"请输入取款金额");
      int s =Integer.parseInt(y);
    
        if(money[c]<s){
        JOptionPane.showMessageDialog(null, "余额不足,请重新输入");
        }
      else{
   
      money[c] =money[c] -s;
     
      String str =JOptionPane.showInputDialog(null, "是否显示余额?y/n");
      if(str.equals("y")){
      cxye();
      }
      }
       }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值