軟體工程作業--ATM自助銀行服務系統

木昔年發表於2020-11-16

部落格班級 AHPU軟體工程
作業要求 ATM自助銀行服務系統
作業目標 編碼實現ATM自助銀行服務系統
學號 3180701118

一、作業要求

編寫一個ATM管理系統,語言不限,要求應包括以下主要功能:

(1)開戶,銷戶

(2)查詢賬戶餘額

(3)存款

(4)取款

(5)轉賬(一個賬戶轉到另一個賬戶)等...

二、程式碼及執行介面

test類

(Java程式的入口)
♡程式碼:

public class Main {
        public static void main(String[] args) {
            bank b=new bank ();
            User u=new User();
            b.menu();
        }
}

User類

(主要是set、get方法和類的構造器)
♡程式碼:

public class User {
    private String name;//姓名
    private int accountId;//賬號
    private String password;//密碼
    private String address;//家庭地址
    private String phone;//聯絡電話
    private double balance;//餘額
    public User(){}
    public User(String name, int accountId, String password, String address, String phone, double balance) {
        this.name = name;
        this.accountId = accountId;
        this.password = password;
        this.address = address;
        this.phone = phone;
        this.balance = balance;
    }

    public String getName(){
        return this.name;
    }
    public void setName(String name){
        this.name=name;
    }


    public int getAccountId(){
        return this.accountId;
    }
    public void setAccountId(int accountId){
        this.accountId=accountId;
    }


    public String getPassword(){
        return this.password;
    }
    public void setPassword(String password){
        this.password=password;
    }


    public String getAddress(){
        return this.address;
    }
    public void setAddress(String address){
        this.address=address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public double getBalance(){
        return this.balance;
    }
    public void setBalance(double balance){
        this.balance=balance;
    }
}

bank類

(實現ATM的操作功能)

1.選單選項(選擇開戶/登入)

♡程式碼:

public void menu() {

        Scanner sc = new Scanner(System.in);
        int ch;
        while(true){
            System.out.println("===========歡迎使用ATM自助銀行服務==========");
            System.out.printf("\t\t\t1、開戶\n\t\t\t2、登入\n\t\t\t0、退出\n");
            System.out.println("============歡迎使用ATM自助銀行服務==========");
            System.out.print("輸入您要操作編號:");
            ch = sc.nextInt();
            switch (ch) {
                case 1:
                    setAccount();//開戶
                    break;
                case 2:
                    onuser = userLogin();//登入
                    if(onuser!=null) menu1();
                    break;
                case 0:    //退出
                    return;
                default:
                    System.out.println("輸入錯誤!請重新輸入!");
                    break;
            }
        }
    }

♡執行介面:

2.開戶

♡程式碼:

//開戶
    public void setAccount() {
            Scanner sc = new Scanner(System.in);
            System.out.print("請輸入姓名:");
            String name = sc.next();
            System.out.print("請輸入家庭地址:");
            String address = sc.next();
            System.out.print("請輸入身份證號:");
            String accountId = sc.next();
            System.out.print("請輸入手機號:");
            String phone=sc.next();
            System.out.print("請輸入銀行卡要設定的密碼:");
            String pwd1 = sc.next();
            System.out.print("請再次輸入密碼:");
            String pwd2 = sc.next();
            if (pwd1.equals(pwd2)) {
                System.out.println(i);
                user[i] = new User(name, i, pwd1, address,phone, 0);
                System.out.println("開戶成功!你的卡號為:" + i);
                i++;
            } else
                System.out.println("兩次密碼不同!請您再一次確認密碼!");
    }

♡執行介面:

3.登入

♡程式碼:

    public User userLogin() {
            Scanner sc = new Scanner(System.in);
            System.out.print("請輸入卡號");
            int aId = sc.nextInt();
            System.out.print("請輸入密碼");
            String pwd = sc.next();
            for (int i = 0; i < user.length; i++) {
                if (user[i] != null) {
                    if (aId == user[i].getAccountId() && pwd.equals(user[i].getPassword())) {
                        System.out.println(user[i].getName() + "先生/女士,歡迎登入!");
                        return user[i];
                    }
                }
            }
            System.out.println("卡號或密碼有誤");
            return null;
    }

♡執行介面:

4.選單選擇(登入成功操作選項)

♡程式碼:

public void menu1(){
        Scanner sc = new Scanner(System.in);
        int ch;
        while(true){
            System.out.println("===========歡迎使用ATM自助銀行服務==========");
            System.out.println("\t\t1、取款\n\t\t2、存款\n\t\t3、查詢餘額\n\t\t4、轉賬\n\t\t5、修改密碼\n\t\t6、銷戶\n\t\t7、重新登入");
            System.out.println("============歡迎使用ATM自助銀行服務==========");
            System.out.print("輸入您要操作編號:");
            ch = sc.nextInt();
            switch (ch) {
                case 1:
                    drawMoney();//取款
                    break;
                case 2:
                    depositMoney();//存款
                    break;
                case 3:
                    showBalance();//查詢餘額
                    break;
                case 4:
                    transferMoney();//轉賬
                    break;
                case 5:
                    updatePassword();//修改密碼
                    break;
                case 6:
                    cancelAccount();//銷戶
                    return;
                case 7:
                    reLogin();//重新登入
                    return;
                default:
                    System.out.println("輸入錯誤!請重新輸入!");
                    break;
            }
        }
    }

♡執行介面:

5.取款

♡程式碼:

    public void drawMoney() {
            Scanner sc = new Scanner(System.in);
            System.out.print("請輸入取款金額:");
            double blc = sc.nextDouble();
            if (blc > onuser.getBalance()) {
                System.out.println("您的餘額不足!無法取錢!");
            } else if (blc <= 0) {
                System.out.println("輸入不正確!");
            } else {
                onuser.setBalance(onuser.getBalance() - blc);
                System.out.println("取錢成功!");
            }
    }

♡執行介面:

6.存款

♡程式碼:

public void depositMoney() {
            Scanner sc = new Scanner(System.in);
            System.out.print("請輸入存款金額:");
            double dsm = sc.nextDouble();
            if (dsm <= 0) {
                System.out.println("輸入不正確!");
            } else {
                onuser.setBalance(onuser.getBalance() + dsm);
                System.out.print(onuser.getBalance());
                System.out.println("存款成功!");
            }
    }

♡執行介面:

7.查詢餘額

♡程式碼:

    public void showBalance() {
            System.out.println("您的餘額為:"+onuser.getBalance() );
    }

♡執行介面:

8.轉賬

♡程式碼:

 public void transferMoney() {
        Scanner sc = new Scanner(System.in);
            System.out.print("請輸入要轉入的卡號;");
            int aId = sc.nextInt();
            if (user[aId] == null) {
                System.out.println("該卡號不存在");
            } else {
                System.out.print("請輸入要轉入金額:");
                double blc = sc.nextDouble();
                if (blc > onuser.getBalance()) {
                    System.out.println("您的餘額不足!無法取錢!");
                } else if (blc <= 0) {
                    System.out.println("輸入不正確");
                } else {
                    onuser.setBalance(onuser.getBalance() - blc);
                    user[aId].setBalance(user[aId].getBalance() + blc);
                    System.out.println("轉賬成功");
                }
            }

    }

♡執行介面:

9.修改密碼

♡程式碼:

public void updatePassword() {
            Scanner sc = new Scanner(System.in);
            System.out.print("請輸入新密碼:");
            String pwd1 = sc.next();
            System.out.print("請再次輸入密碼:");
            String pwd2 = sc.next();
            if (pwd1.equals(pwd2)) {
               onuser.setPassword(pwd1);
                System.out.println("修改成功!");
            } else
                System.out.println("兩次密碼不同,請確認密碼!");

    }

♡執行介面:

10.銷戶

♡程式碼:

public void cancelAccount() {
            user[onuser.getAccountId()] = null;
            System.out.println("登出成功");
            reLogin();
    }

♡執行介面:

11.重新登陸

♡程式碼:

 public void reLogin() {
            onuser = null;
            System.out.println("歡迎下次光臨!");
    }

三、作業小結

psp表格

psp2.1 任務內容 計劃完成需要的時間(min) 實際完成需要的時間(min)
Planning 計劃 180 240
Development 開發 120 150
Analysis 需求分析(包括學習新技術) 10 10
Design Spec 生成設計文件 30 40
Design Review 設計複審 5 10
Coding Standard 程式碼規範 5 10
Design 具體設計 20 40
Coding 具體編碼 120 180
Code Review 程式碼複審 5 7
Test 測試(自我測試,修改程式碼,提交修改) 10 15
Reporting 報告 20 60
Test Report 測試報告 5 5
Size Measurement 計算工作量 5 10
Postmortem & Process Improvement Plan 事後總結,並提出過程改進計劃 10 15

心得和經驗

本次作業用Java實現,由於未上過Java課,都Java不熟練,所以用簡單的類編寫,未用GUI實現圖形化。

相關文章