银行案例

2022/6/4 23:50:19

本文主要是介绍银行案例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Bank.java

package com.ht.back;

import java.util.Scanner;

public class Back {
    static Scanner input = new Scanner(System.in);
    static User user = new User();
    static User[] users = new User[5];
    public void init() {
        user.setBalance(30000000.0);
        user.setCardNo("22222222");
        user.setPassword("22222222");
        user.setUsername("ht");
        user.setIdentityCard("422");
        user.setPhone("12345678901");
        users[0] = user;
        User user2 = new User("3333333","3333333","ht2","432","11112222333344",56666666.0);
        users[1] = user2;
        users[2] = new User("4444444","44444","ht3","433","4444444",4444444.0);
        users[3] = new User("5555555555","55555","ht4","433","5555555",555555555.0);
        users[4] = new User("6666666666","666666","ht5","433","66666",666666.0);
    }
    public void login() {
        System.out.println("请输入卡号:");
        String no = input.next();
        System.out.println("请输入密码:");
        String pwd = input.next();
        for(int i = 0; i < users.length ; i++) {
            if(no.equals(users[i].getCardNo())  && pwd.equals(users[i].getPassword())){
                System.out.println("欢迎您" + users[i].getUsername());    
            };
        }
        
    }
    
    public void showMeun() {
        
        int choice;
        do {//这里不是最终版 后期更新
            System.out.println("--------------欢迎使用ATM自动银行系统----------------------------");
            System.out.println("1.开户2.存款3.取款4.转账5.查询余额6.修改密码7.修改预留手机号8.注销账号0.退出");
            System.out.println("----------------------------------------");
            System.out.println("请输入操作编号");
            choice = input.nextInt();
            switch(choice) {
            case 1:
                System.out.println("执行开户");
                break;
            case 2:
                System.out.println("执行存款");
                break;
            case 3:
                System.out.println("执行取款");
                break;
            case 4:
                System.out.println("执行转账");
                break;
            case 5:
                System.out.println("执行查询余额");
                break;
            case 6:
                System.out.println("执行修改密码");
                break;
            case 7:
                System.out.println("执行修改预留手机号");
                break;
            case 8:
                System.out.println("执行注销账号");
                break;
            case 0:
                System.out.println("执行退出");
                return;
            default:
                System.out.println("输入有误请重新输入");    
                break;
            }
    }while(choice <0||choice >8);
    }


}

User.java

package com.ht.back;

public class User {
    private String cardNo;
    private String password;
    private String username;
    private String identityCard;
    private String phone;
    private double balance;
    public User() {}
    public User(String cardNo, String password, String username, String identityCard, String phone, double balance) {
        super();
        this.cardNo = cardNo;
        this.password = password;
        this.username = username;
        this.identityCard = identityCard;
        this.phone = phone;
        this.balance = balance;
    }
    public String getCardNo() {
        return cardNo;
    }
    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getIdentityCard() {
        return identityCard;
    }
    public void setIdentityCard(String identityCard) {
        this.identityCard = identityCard;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public double getBalance() {
        return balance;
    }
    public void setBalance(double balance) {
        this.balance = balance;
    };
}

TestBank.java

package com.ht.back;


public class TestBack {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Back bank = new Back();
        bank.init();
        bank.login();
        bank.showMeun();
    }

}

这三个文件都在同一个包下运行



这篇关于银行案例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程