zoukankan      html  css  js  c++  java
  • ATM测试

    ATM机

    一 、数据成员:

    变量accountID为字符串类型String,用于存储学生的用户账号(由八位数字组成)。

    变量accountname为字符串类型String,用于存储账户的名称。

    变量operatedate为字符串类型String,用于存储操作的时间,由十位字符组成,显示格式为“2018-09-20”。    

    变量operatetypeint类型,用于存储操作账户的类型,具体描述为“1”表示存款,“2”表示取款,“3”表示转账汇款,“4”表示修改账户密码,“5”表示查询余额。

    变量accountpassword为字符串类型String,用于用户密码,由六位数字组成。

    变量accountbalance为整数类型int,用于存储账户余额,缺省为0。

    变量amount为整数类型int,表示操作流水金额。


    二、功能要求:

    1.对每个变量定义get()(读取变量信息)和set()(设置变量信息)的方法。

    2.定义accountinformation.txt作为账户基本信息库,基本信息包括accountID,accountname,accountpassword, accountbalance,要求事先实现至少存储五个账户的信息,定义accountlist.txt作为账户操作流水信息数据库,操作流水信息包括(accountID,accountname,operatedate,operatetype, amount)。

    3.该程序模拟ATM的功能设计,当用户插卡后显示,输入密码界面,用户输入正确密码(用户输入错误密码,则提示该卡已被锁定,无法操作),则弹出选择界面:存款、取款、转账汇款、修改密码、查询余额。


    三、分析

    1.本次实验我用了数组来实现。首先定义了Account对象数组用来存储五个账户的信息,包括用户账号、账户名称、用户密码和账户余额。

    2.该程序会重复打印“欢迎用户使用中国工商银行自主柜员系统”,因此建立一个play()方法

    1 public static void play() {
    2         System.out.println("********************************************************");
    3         System.out.println(" 欢迎" + user[num].getAccountname() + "使用中国工商银行自主柜员系统");
    4         System.out.println("********************************************************");
    5     }

    3.利用switch()语句完成主界面的功能操作,利用case语句分开,分别执行选择对应的功能

    4.该程序会多次用到判断账户余额是否充足的方法,因此建立一个panduan()方法

     1 public static int panduan(int a) {
     2         int t = 0;
     3         if (a <= user[num].getAccountbalance()) {
     4             t = 1;
     5         }
     6         if (a > user[num].getAccountbalance()) {
     7             t = -1;
     8         }
     9         return t;
    10     }

    5.可以设置全局变量返回插卡用户在数组中的位置,方便于以后的功能操作

    6.最重要的是完成界面的跳转功能

    7.缺点:利用数组未能实现保存用户的清单信息,无法保存每次操作日期、操作类型和操作金额,不能很好地实现最后一个查询流水的功能。这就需要依靠文件来完成。


    四、代码:

      1 package com.test;
      2 
      3 //信1905-1 20194024 张紫诺
      4 import java.util.Scanner;
      5 
      6 class Account {
      7     private String acountID; // 用户账号
      8     private String accountname; // 账户名称
      9     private String operatedate; // 操作时间
     10     private int operatetype; // 账户类型
     11     private String accountpassword; // 用户密码
     12     private int accountbalance; // 存储账户余额
     13     private int amount; // 操作流水金额
     14 
     15     public String getAcountID() {
     16         return acountID;
     17     }
     18 
     19     public void setCcountID(String ccountID) {
     20         this.acountID = ccountID;
     21     }
     22 
     23     public String getAccountname() {
     24         return accountname;
     25     }
     26 
     27     public void setAccountname(String accountname) {
     28         this.accountname = accountname;
     29     }
     30 
     31     public String getOperatedate() {
     32         return operatedate;
     33     }
     34 
     35     public void setOperatedate(String operatedate) {
     36         this.operatedate = operatedate;
     37     }
     38 
     39     public int getOperatetype() {
     40         return operatetype;
     41     }
     42 
     43     public void setOperatetype(int operatetype) {
     44         this.operatetype = operatetype;
     45     }
     46 
     47     public String getAccountpassword() {
     48         return accountpassword;
     49     }
     50 
     51     public void setAccountpassword(String accountpassword) {
     52         this.accountpassword = accountpassword;
     53     }
     54 
     55     public int getAccountbalance() {
     56         return accountbalance;
     57     }
     58 
     59     public void setAccountbalance(int accountbalance) {
     60         this.accountbalance = accountbalance;
     61     }
     62 
     63     public int getAmount() {
     64         return amount;
     65     }
     66 
     67     public void setAmount(int amount) {
     68         this.amount = amount;
     69     }
     70 
     71     public Account() {
     72     }
     73 
     74     public Account(String ccountID, String accountname, String accountpassword, int accountbalance) {
     75         this.acountID = ccountID;
     76         this.accountname = accountname;
     77         this.accountpassword = accountpassword;
     78         this.accountbalance = accountbalance;
     79     }
     80 }
     81 
     82 public class AccountManager {
     83     static Account user[] = new Account[5];
     84     static int num;
     85     static Scanner in = new Scanner(System.in);
     86 
     87     public AccountManager() {
     88         for (int i = 0; i < 5; i++) {
     89             user[i] = new Account();
     90         }
     91         user[0] = new Account("20194019", "小一", "000000", 500);
     92         user[1] = new Account("20194020", "小明", "111111", 1000);
     93         user[2] = new Account("20194021", "赵经", "222222", 300);
     94         user[3] = new Account("20194022", "马第", "333333", 5000);
     95         user[4] = new Account("20194023", "丽华", "444444", 10000);
     96     }
     97 
     98     // 打印
     99     public static void play() {
    100         System.out.println("********************************************************");
    101         System.out.println(" 欢迎" + user[num].getAccountname() + "使用中国工商银行自主柜员系统");
    102         System.out.println("********************************************************");
    103     }
    104 
    105     // 输入账号操作
    106     public static void inputAccount() {
    107         System.out.println("***********************************");
    108         System.out.println("   欢迎使用中国工商银行自动柜员系统   ");
    109         System.out.println("***********************************");
    110         System.out.print("       请输入您的账号:");
    111         String number = in.next();
    112         System.out.println("***********************************");
    113         if (number.length() != 8) {
    114             System.out.println("该卡不是工行卡");
    115             inputAccount();
    116         }
    117         for (int i = 0; i < 5; i++) {
    118             if (number.equals(user[i].getAcountID())) {
    119                 num = i;
    120                 inputPassword();
    121                 break;
    122             }
    123         }
    124         System.out.println("该账号不存在");
    125         inputAccount();
    126     }
    127 
    128     // 输入密码界面操作
    129     public static void inputPassword() {
    130         int m = 0;
    131         String password;
    132         while (m != 3) {
    133             play();
    134             System.out.print("            请输入您的密码:");
    135             password = in.next();
    136             System.out.println("*******************************************************");
    137             if ((password.length() != 6) || (password.compareTo(user[num].getAccountpassword()) != 0)) {
    138                 System.out.println("密码录入错误");
    139                 m++;
    140             }
    141             if (password.compareTo(user[num].getAccountpassword()) == 0) {
    142                 menu();
    143                 break;
    144             }
    145         }
    146         if (m == 3) {
    147             System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理");
    148             inputAccount();
    149         }
    150     }
    151 
    152     // 主界面
    153     public static void display() {
    154         play();
    155         System.out.println("                     1、存款");
    156         System.out.println("                     2、取款");
    157         System.out.println("                     3、转账汇款");
    158         System.out.println("                     4、修改密码");
    159         System.out.println("                     5、查询余额");
    160         System.out.println("*********************************************************");
    161     }
    162 
    163     // 主界面操作
    164     public static void menu() {
    165         int m;
    166         display();
    167         System.out.print("请输入你要执行的操作:");
    168         m = in.nextInt();
    169         switch (m) {
    170         case 1:
    171             cunkuan();
    172             break;
    173         case 2:
    174             qukuan();
    175             break;
    176         case 3:
    177             zhuanzhang();
    178             break;
    179         case 4:
    180             xiugai();
    181             break;
    182         case 5:
    183             chaxun();
    184             break;
    185         default:
    186             break;
    187         }
    188     }
    189 
    190     // 存款
    191     public static void cunkuan() {
    192         String money;
    193         double d;
    194         String ch;
    195         play();
    196         System.out.print("                 请输入存款金额:");
    197         money = in.next();
    198         System.out.println("********************************************************");
    199         d = Double.parseDouble(money);
    200         if (d % 1 != 0 || d <= 0) {
    201             System.out.println("输入金额有误");
    202             cunkuan();
    203         }
    204         if (money.equals("q")) {
    205             inputAccount();
    206         } else {
    207             user[num].setAccountbalance(user[num].getAccountbalance() + (int) d);
    208             play();
    209             System.out.println("              当前账户存款操作成功。");
    210             System.out.println("              当前账户余额为:" + user[num].getAccountbalance() + "元");
    211             System.out.println("********************************************************");
    212 
    213             System.out.println("提示:请单击“q”键退出");
    214             ch = in.next();
    215             if (ch.equals("q")) {
    216                 inputAccount();
    217             }
    218         }
    219 
    220     }
    221 
    222     // 取款菜单
    223     public static void display2() {
    224         play();
    225         System.out.println("          当前账户每日可以支取2万元。");
    226         System.out.println("               1、100元");
    227         System.out.println("               2、500元");
    228         System.out.println("               3、1000元");
    229         System.out.println("               4、1500元");
    230         System.out.println("               5、2000元");
    231         System.out.println("               6、5000元");
    232         System.out.println("               7、其他金额");
    233         System.out.println("               8、退卡");
    234         System.out.println("               9、返回");
    235         System.out.println("********************************************************");
    236     }
    237 
    238     // 判断余额
    239     public static int panduan(int a) {
    240         int t = 0;
    241         if (a <= user[num].getAccountbalance()) {
    242             t = 1;
    243         }
    244         if (a > user[num].getAccountbalance()) {
    245             t = -1;
    246         }
    247         return t;
    248     }
    249 
    250     // 取款
    251     public static void qukuan() {
    252         display2();
    253         int a;
    254         System.out.print("请输入您要执行的操作:");
    255         a = in.nextInt();
    256         switch (a) {
    257         case 1: {
    258             if (panduan(100) == -1) {
    259                 System.out.println("账户余额不足");
    260             } else {
    261                 user[num].setAccountbalance(user[num].getAccountbalance() - 100);
    262                 play();
    263                 System.out.println("          当前账户取款操作100元成功。");
    264                 System.out.println("          当前账户余额为:" + user[num].getAccountbalance() + "元");
    265                 System.out.println("********************************************************");
    266             }
    267             break;
    268         }
    269         case 2: {
    270             if (panduan(500) == -1) {
    271                 System.out.println("账户余额不足");
    272             } else {
    273                 user[num].setAccountbalance(user[num].getAccountbalance() - 500);
    274                 play();
    275                 System.out.println("          当前账户取款操作500元成功。");
    276                 System.out.println("          当前账户余额为:" + user[num].getAccountbalance() + "元");
    277                 System.out.println("********************************************************");
    278             }
    279             break;
    280         }
    281         case 3: {
    282             if (panduan(1000) == -1) {
    283                 System.out.println("账户余额不足");
    284             } else {
    285                 user[num].setAccountbalance(user[num].getAccountbalance() - 1000);
    286                 play();
    287                 System.out.println("          当前账户取款操作1000元成功。");
    288                 System.out.println("          当前账户余额为:" + user[num].getAccountbalance() + "元");
    289                 System.out.println("********************************************************");
    290             }
    291             break;
    292         }
    293         case 4: {
    294             if (panduan(1500) == -1) {
    295                 System.out.println("账户余额不足");
    296             } else {
    297                 user[num].setAccountbalance(user[num].getAccountbalance() - 1500);
    298                 play();
    299                 System.out.println("          当前账户取款操作1500元成功。");
    300                 System.out.println("          当前账户余额为:" + user[num].getAccountbalance() + "元");
    301                 System.out.println("********************************************************");
    302             }
    303             break;
    304         }
    305         case 5: {
    306             if (panduan(2000) == -1) {
    307                 System.out.println("账户余额不足");
    308             } else {
    309                 user[num].setAccountbalance(user[num].getAccountbalance() - 2000);
    310                 play();
    311                 System.out.println("          当前账户取款操作2000元成功。");
    312                 System.out.println("          当前账户余额为:" + user[num].getAccountbalance() + "元");
    313                 System.out.println("********************************************************");
    314             }
    315             break;
    316         }
    317         case 6: {
    318             if (panduan(5000) == -1) {
    319                 System.out.println("账户余额不足");
    320             } else {
    321                 user[num].setAccountbalance(user[num].getAccountbalance() - 5000);
    322                 play();
    323                 System.out.println("          当前账户取款操作5000元成功。");
    324                 System.out.println("          当前账户余额为:" + user[num].getAccountbalance() + "元");
    325                 System.out.println("********************************************************");
    326             }
    327             break;
    328         }
    329         case 7: {
    330             int mm;
    331             play();
    332             System.out.println("                请输入取款金额 ");
    333             mm = in.nextInt();
    334             System.out.println("********************************************************");
    335             if (panduan(mm) == -1) {
    336                 System.out.println("账户余额不足");
    337             } else {
    338                 user[num].setAccountbalance(user[num].getAccountbalance() - mm);
    339                 play();
    340                 System.out.println("          当前账户取款操作" + mm + "元成功。");
    341                 System.out.println("          当前账户余额为:" + user[num].getAccountbalance() + "元");
    342                 System.out.println("********************************************************");
    343             }
    344         }
    345         case 8:
    346             inputAccount();
    347             break;
    348         case 9:
    349             menu();
    350             break;
    351         }
    352         String ch;
    353         System.out.println("提示:请单击“q”键退出");
    354         ch = in.next();
    355         if (ch.equals("q")) {
    356             inputAccount();
    357         }
    358     }
    359 
    360     // 转账
    361     public static void zhuanzhang() {
    362         int num1, money;
    363         String name1;
    364         play();
    365         System.out.print("            请输入转账账户:");
    366         name1 = in.next();
    367         for (int i = 0; i < 5; i++) {
    368              if(name1.equals(user[i].getAcountID())){
    369                 num1 = i;
    370                 play();
    371                 System.out.print("              请输入转账金额:");
    372                 money = in.nextInt();
    373                 System.out.println("********************************************************");
    374                 if (panduan(money) == -1) {
    375                     System.out.println("账户余额不足");
    376                 } else {
    377                     play();
    378                     System.out.println("    请确认是否向*" + user[num1].getAccountname() + "转账" + money + "元。(Y/N)");
    379                     System.out.println("********************************************************");
    380                     String f = in.next();
    381                     if (f.equals("N")) {
    382                         display();
    383                     }
    384                     if (f.equals("Y")) {
    385                         user[num].setAccountbalance(user[num].getAccountbalance() + money);
    386                         user[num].setAccountbalance(user[num].getAccountbalance() - money);
    387                         play();
    388                         System.out.println("        当前账户向*" + user[num1].getAccountname() + "转账" + money + "元。");
    389                         System.out.println("          当前账户余额为:" + user[num].getAccountbalance() + "元");
    390                         System.out.println("********************************************************");
    391                     }
    392                 }
    393             }else {
    394                 System.out.println("该账户不存在");
    395             }
    396             System.out.println("提示:点击“q”键退出");
    397             String ch = in.next();
    398             if (ch.equals("q")) {
    399                 inputAccount();
    400             }
    401         }
    402 
    403     }
    404 
    405     // 修改
    406     public static void xiugai() {
    407         String a;
    408         String b;
    409         String c;
    410         System.out.println("********************************************************");
    411         System.out.println(" 欢迎" + user[num].getAccountname() + "使用中国工商银行自主柜员系统");
    412         System.out.println("********************************************************");
    413         System.out.print("请输入当前密码:");
    414         a = in.next();
    415         if (!a.equals(user[num].getAccountpassword())) {
    416             System.out.println("当前密码录入错误");
    417             xiugai();
    418         }
    419         System.out.print("请输入修改密码:");
    420         b = in.next();
    421         System.out.print("请输入确认密码:");
    422         c = in.next();
    423         if (!b.equals(c)) {
    424             System.out.println("修改密码与确认密码不一致");
    425             xiugai();
    426         } else {
    427             user[num].setAccountpassword(b);
    428             System.out.println("********************************************************");
    429             System.out.println(" 欢迎" + user[num].getAccountname() + "使用中国工商银行自主柜员系统");
    430             System.out.println("********************************************************");
    431             System.out.println("      当前账户密码修改成功");
    432             System.out.println("********************************************************");
    433             inputAccount();
    434         }
    435         
    436     }
    437 
    438     // 查询
    439     public static void chaxun() {
    440         String m;
    441         System.out.println("********************************************************");
    442         System.out.println(" 欢迎" + user[num].getAccountname() + "使用中国工商银行自主柜员系统");
    443         System.out.println("********************************************************");
    444         System.out.println("       当前账户余额为:" + user[num].getAccountbalance() + "元");
    445         System.out.println("       账户清单信息为:");
    446 
    447         System.out.println("********************************************************");
    448         System.out.println("提示:点击“q”键,退出系统");
    449         m = in.next();
    450         if (m.equals("q")) {
    451             inputAccount();
    452         }
    453     }
    454 
    455     public static void main(String[] args) {
    456         AccountManager acc=new AccountManager();
    457         inputAccount();
    458     }
    459 }

     

    五、测试截图:

    1.插卡并输入密码

    2.存款操作

     

    3.取款操作

     

    4.转账汇款操作

     

    5.修改密码操作

     

    6.查询余额操作

     

  • 相关阅读:
    Android 网络加载动态库 .so
    利用input新类型,解决移动端原生实现日期时间联动问题,精确到分
    简单对React入个门-个人总结
    三种方式创建Angular的自定义服务
    Angular的自定义指令-个人总结
    利用Angular的自定义过滤器功能实现单词的首字母大写
    简单小例子带你明白Angular的MVVM思想
    Angular基础引导(1)
    JavaScript简单拖拽事件(鼠标跟随事件)
    简单数组去重
  • 原文地址:https://www.cnblogs.com/znjy/p/13715656.html
Copyright © 2011-2022 走看看