zoukankan      html  css  js  c++  java
  • Java课堂测试01及感想

      上周进行了Java的开学第一次测验,按要求做一个模拟ATM机功能的程序,实现存取款、转账汇款、修改密码、查询余额的操作。这次测验和假期的试题最大的不同还是把数组存储改成的文件存储,在听到老师说要用文件的时候,还是有种悔不当初的感觉的,假期里找的教程是有教文件的,当时想着假期给的试题仅要求数组,就偷了懒。这次测验的时候,看了一下文件的教程,不是怎么清楚怎么像题目那样使用文件,便放弃了这一部分,还是用的数组。这次测验还发现了自己的很多问题,特别是一些习惯上的问题。以前写的都是几十行的小程序,简单看下题目就知道该怎么做,而这次的测验却没那么小了。拿到题目的时候老师有叫过我们先构思,不要立刻动手,我看了题目想了一会儿,并没有很清楚的思路,只有一个模糊的想法,就开始动手,写到执行文件时就不太记得一开始的想法,写一会就看一会题目,翻翻刚写的代码,浪费了很多时间。写着写着就发现少了一些东西,又去前面加,后面都乱了。测试的时间从两个小时延长到两个半小时再到三个小时,可以说是很足了,但是我还是只实现了前面两个功能,也是和思路的混乱有关,当然更主要的是能力不足,暑假的学习太过应付了事,以后还是要努力才行,不能再贪玩了。

    Account.java

     1 public class Account {
     2     
     3     private String accountID;      //账号
     4     private String accountname;       //名称
     5     private String operatedate;        //操作时间
     6     private int operatetype;
     7     private String accountpassword;    //密码
     8     private int accountbalance;        //账户余额
     9     private int amount;                //流水金额
    10     
    11     public String getAccountID() {
    12         return accountID;
    13     }
    14     public void setAccountID(String accountID) {
    15         this.accountID = accountID;
    16     }
    17     public String getAccountname() {
    18         return accountname;
    19     }
    20     public void setAccountname(String accountname) {
    21         this.accountname = accountname;
    22     }
    23     public String getOperatedate() {
    24         return operatedate;
    25     }
    26     public void setOperatedate(String operatedate) {
    27         this.operatedate = operatedate;
    28     }
    29     public int getOperatetype() {
    30         return operatetype;
    31     }
    32     public void setOperatetype(int operatetype) {
    33         this.operatetype = operatetype;
    34     }
    35     public String getAccountpassword() {
    36         return accountpassword;
    37     }
    38     public void setAccountpassword(String accountpassword) {
    39         this.accountpassword = accountpassword;
    40     }
    41     public int getAccountbalance() {
    42         return accountbalance;
    43     }
    44     public void setAccountbalance(int accountbalance) {
    45         this.accountbalance = accountbalance;
    46     }
    47     public int getAmount() {
    48         return amount;
    49     }
    50     public void setAmount(int amount) {
    51         this.amount = amount;
    52     }
    53     
    54     Account( String accountID,String accountname,String accountpassword){
    55         this.accountID = accountID;
    56         this.accountname = accountname;
    57         this.accountpassword = accountpassword;
    58         accountbalance = 0;
    59     }
    60     
    61 }

    AccountManager.java

    import java.util.Scanner;
    
    public class AccountManager {
        
        Scanner in = new Scanner( System.in );
        Account[] acc = new Account[1000];
        int i=5;
        int j,k;
        int temp = 0;
        
        public void InterfaceAccount(){
            acc[0] = new Account("20173445","刘**","123456");
            acc[1] = new Account("20170001" ,"张三","387592");
            acc[2] = new Account("20170002","李四","035432");
            acc[3] = new Account("20170004","王五","830294");
            acc[4] = new Account("20170005","赵六","208493");
            temp=0;
            String accountID;
            System.out.println("**************************************************");
            System.out.println("          欢迎使用中国工商银行自动柜员系统");
            System.out.println("**************************************************");
            System.out.print("      请输入您的账号:");
            accountID = in.next();
            if( accountID.length() != 8 ){
                System.out.println("**************************************************");
                System.out.println("该卡不是工行账号");
                InterfaceAccount();
            }
            else{
                for( j=0; (j<i) && (temp==0); j++ ){
                    if( acc[j].getAccountID().equals( accountID ))
                        temp = 1;
                }
                if(temp==0){
                    System.out.println("**************************************************");
                    System.out.println("该账号不存在");
                    InterfaceAccount();
                }
                else{
                    j--;
                    InterfacePassword();
                }
            }
        }
        
        public void InterfacePassword(){
            String accountpassword;
            int h=3;
            System.out.println("**************************************************");
            System.out.println("      欢迎"+acc[j].getAccountname()+"使用中国工商银行自动柜员系统");
            System.out.println("**************************************************");
            while((h--)>0){
                System.out.print("  请输入您的密码:");
                accountpassword = in.next();
                if( acc[j].getAccountpassword().equals( accountpassword)){
                    InterfaceMain();
                }
                else{
                    System.out.println("**************************************************");
                    System.out.println("密码输入错误");
                    if( h==0){
                        System.out.println("**************************************************");
                        System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理");
                        InterfaceAccount();
                    }
                }
            }
        }
        
        public void InterfaceMain(){
            int operatetype;
            System.out.println("**************************************************");
            System.out.println("      欢迎"+acc[j].getAccountname()+"使用中国工商银行自动柜员系统");
            System.out.println("**************************************************");
            System.out.println("                  1、 存款;");
            System.out.println("                  2、 取款;");
            System.out.println("                  3、 转账汇款;");
            System.out.println("                  4、 修改密码;");
            System.out.println("                  5、 查询余额");
            System.out.println("**************************************************");
            operatetype = in.nextInt();
            acc[j].setOperatetype(operatetype);
            switch(operatetype){
            case 1:deposit();break;
            case 2:withdraw();break;
            }
        }
        
        public void deposit(){                //存款
            int amount;
            System.out.println("**************************************************");
            System.out.println("      欢迎"+acc[j].getAccountname()+"使用中国工商银行自动柜员系统");
            System.out.println("**************************************************");
            System.out.println("              请输入存款金额:");
            amount = in.nextInt();
            String s = String.valueOf(amount);
            if( s.equals("q"))
                InterfaceAccount();
            else{
                if( amount <= 0 ){
                    System.out.println("输入金额有误");
                    withdraw();
                }
                else{
                    System.out.println("**************************************************");
                    System.out.println("      欢迎"+acc[j].getAccountname()+"使用中国工商银行自动柜员系统");
                    System.out.println("**************************************************");
                    System.out.println("             当前账户存款操作成功");
                    acc[j].setAccountbalance( acc[j].getAccountbalance()+amount );
                    System.out.println("  当前账户余额为:"+acc[j].getAccountbalance()+"元");
                    System.out.println("**************************************************");
                    s = in.next();
                    if( s.equals("q"))
                        InterfaceAccount();
                }
            }
        }
        
        public void withdraw(){                                    //取款
            int amount = 0;
            System.out.println("**************************************************");
            System.out.println("     欢迎"+acc[j].getAccountname()+"使用中国工商银行自动柜员系统");
            System.out.println("**************************************************");
            System.out.println("          当前账户每日可以支取2万元");
            System.out.println("                 1、 100元");
            System.out.println("                 2、 500元");
            System.out.println("                 3、 1000元");
            System.out.println("                 4、 1500元");
            System.out.println("                 5、 2000元");
            System.out.println("                 6、 5000元");
            System.out.println("                 7、 其他金额");
            System.out.println("                 8、 退卡");
            System.out.println("                 9、 返回");
            System.out.println("**************************************************");
            temp = in.nextInt();
            switch(temp){
                case 1:amount=100;break;
                case 2:amount=500;break;
                case 3:amount=1000;break;
                case 4:amount=1500;break;
                case 5:amount=2000;break;
                case 6:amount=5000;break;
                case 7:{
                    System.out.println("**************************************************");
                    System.out.println("     欢迎"+acc[j].getAccountname()+"使用中国工商银行自动柜员系统");
                    System.out.println("**************************************************");
                    System.out.println("                请输入取款金额");
                    amount = in.nextInt();break;
                }
                default:break;
            }
            if( amount > acc[j].getAccountbalance() )
                System.out.println("账户余额不足");
            else{
                System.out.println("**************************************************");
                System.out.println("  欢迎"+acc[j].getAccountname()+"使用中国工商银行自动柜员系统");
                System.out.println("**************************************************");
                System.out.println("当前账户取款操作"+amount+"元成功");
                acc[j].setAccountbalance( acc[j].getAccountbalance()+amount);
                System.out.println("当前账户余额为:"+acc[j].getAccountbalance()+"元");
                System.out.println("**************************************************");
            }
            if( temp == 8 )
                InterfaceAccount();
            if(temp==9)
                InterfaceMain();
        }
        
    }

    ATM.java

    /*
     * 信1705-1
     * 20173445
     * 刘
     */
    public class ATM {
        public static void main( String[] args){
            AccountManager manager = new AccountManager();
            manager.InterfaceAccount();
        }
    }
  • 相关阅读:
    君子藏器于身,伺时而动
    高级前端面试集锦
    ES6标准入门(第三版).pdf----推荐指数⭐⭐⭐⭐⭐
    《Vue.js实战》--推荐指数⭐⭐⭐⭐
    如何让vue自定义组件可以包裹内容,并且渲染出来,以及组件的组合使用
    vue里如何灵活的绑定class以及内联style
    为什么VUE注册组件命名时不能用大写的?
    在github上搭建一个静态的个人网站
    leetcode-6-basic
    leetcode-5-basic
  • 原文地址:https://www.cnblogs.com/gothic-death/p/9697332.html
Copyright © 2011-2022 走看看