???懵

软件工程第三次作业

博客班级 https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18
作业要求 https://edu.cnblogs.com/campus/ahgc/AHPU-se-JSJ18/homework/11478
作业目标 编写一个ATM管理系统,语言不限,要求应包括以下主要功能:

(1)开户,销户

(2)查询账户余额

(3)存款

(4)取款

(5)转账(一个账户转到另一个账户)等...
学号 3180701238
代码如下: //用户登录
public void login() {
System.out.print("请输入卡号:");
int no = input.nextInt();
System.out.print("请输入密码(8~16位):");
String pwd = input.next();
User check = loginCheck(no, pwd);

    if (check != null) {
        this.showMenu(check);
    } else {
        System.out.println("用户名或密码错误!请重新输入!");
        this.login();
    }
}

//开户
public void register() {
System.out.print("请输入姓名:");
String userName = input.next();
String identity;
do {
System.out.print("请输入身份证号码:");
identity = input.next();
} while (identity.length() != 18);
String phone;
do {
System.out.print("请输入预存手机号码:");
phone = input.next();
} while (phone.length() != 11);
String passWord;
do {
System.out.print("请输入密码:");
passWord = input.next();
} while (passWord.length() < 8 || passWord.length() > 16);//密码8~16位
double money;
do {
System.out.print("请输入预存金额(大于等于10元):");
money = input.nextInt();
} while (money < 10);

    User user = new User();
    user.setCardNo(cardNo);
    user.setUserName(userName);
    user.setIdentity(identity);
    user.setPhone(phone);
    user.setPassWord(passWord);
    user.setBalance(money);
    System.out.println("开户成功!您的卡号为:" + cardNo);
    cardNo++;
    //将该对象存储到users数组中
    //扩容判断
    if (size > (users.length - 1)) {
        User[] newUsers = Arrays.copyOf(users, size + 1);
        users = newUsers;
        users[size] = user;
    }
    size++;
}

//存款
public void deposit(User user) {
System.out.print("请输入存款金额:");
double money = input.nextDouble();
user.setBalance(user.getBalance() + money);
System.out.println("存款成功!");
}

//取款
public void withdraw(User user) {
System.out.print("请输入取款金额:");
double money = input.nextDouble();
if (money <= user.getBalance()) {
user.setBalance(user.getBalance() - money);
System.out.println("取款成功!当前余额为:" + user.getBalance() + "元!");
} else {
System.out.println("余额不足!");
}
}
//注销账户
public void cancel(User user) {
int index = size + 1;
for (int i = 0; i < size; i++) {
// size不需要非空判断
// if (users[i] != null) {
if (users[i] == user) {
index = i;
break;
}
// }
}
//移动该元素之后的每个元素
for (int i = index; i < size - 1; i++) {
users[i] = users[i + 1];
}
size--;
System.out.println("注销成功!");
}
}

源代码:
import java.util.Arrays;
import java.util.Scanner;

public class Bank {
Scanner input = new Scanner(System.in);

User[] users = new User[3];

int cardNo = 4;
int size = 3;


public Bank() {      //初始方法(如果存在一些程序起始时必须要执行的代码,则写入初始化方法initial中)

    User user = new User();
    user.setCardNo(1);
    user.setIdentity("131000199811111234");
    user.setUserName("Ziph");
    user.setPassWord("12345678");
    user.setPhone("12345670000");
    user.setBalance(1000.00);
    users[0] = user;

    users[1] = new User();
    users[1].setCardNo(2);
    users[1].setIdentity("131000111111114567");
    users[1].setUserName("小王");
    users[1].setPassWord("12345678");
    users[1].setPhone("12345670001");
    users[1].setBalance(2000.00);

    users[2] = new User(3, "131000199811115678"
            , "小明", "12345678"
            , "12345670002", 3000.00);
}

public void login() {
    System.out.print("请输入卡号:");
    int no = input.nextInt();
    System.out.print("请输入密码(8~16位):");
    String pwd = input.next();
    User check = loginCheck(no, pwd);

    if (check != null) {
        this.showMenu(check);
    } else {
        System.out.println("用户名或密码错误!请重新输入!");
        this.login();
    }
}

public void register() {
    System.out.print("请输入姓名:");
    String userName = input.next();
    String identity;
    do {
        System.out.print("请输入身份证号码:");
        identity = input.next();
    } while (identity.length() != 18);
    String phone;
    do {
        System.out.print("请输入预存手机号码:");
        phone = input.next();
    } while (phone.length() != 11);
    String passWord;
    do {
        System.out.print("请输入密码:");
        passWord = input.next();
    } while (passWord.length() < 8 || passWord.length() > 16);//密码8~16位
    double money;
    do {
        System.out.print("请输入预存金额(大于等于10元):");
        money = input.nextInt();
    } while (money < 10);


    User user = new User();
    user.setCardNo(cardNo);
    user.setUserName(userName);
    user.setIdentity(identity);
    user.setPhone(phone);
    user.setPassWord(passWord);
    user.setBalance(money);
    System.out.println("开户成功!您的卡号为:" + cardNo);
    cardNo++;
    if (size > (users.length - 1)) {
        User[] newUsers = Arrays.copyOf(users, size + 1);
        users = newUsers;
        users[size] = user;
    }
    size++;
}

public User loginCheck(int no, String pwd) {
    for (int i = 0; i < size; i++) {
        //验证卡号、密码
        if (users[i] != null) {//非空判断
            if ((no == users[i].getCardNo() && pwd.equals(users[i].getPassWord()))) {
                return users[i];
            }
        }
    }
    return null;
}

public User transferCheck(int no) {
    for (int i = 0; i < users.length; i++) {
        //校验卡号
        if (users[i] != null) {
            if (no == users[i].getCardNo()) {
                return users[i];
            }
        }
    }
    return null;
}

public void welcomeMenu() {
    System.out.println("-------欢迎使用中国建设银行ATM自助服务-------");
    System.out.println("---      1.登录    2.开户    0.退出     ---");
    System.out.println("------------------------------------------");
    System.out.print("请输入操作编码:");
    int choice = input.nextInt();
    switch (choice) {
        case 1:
            this.login();
            break;
        case 2:
            this.register();
            this.welcomeMenu();
            break;
        case 0:
            exit();
        default:
            System.out.println("输入有误!请重新输入!");
    }
}

public void exit() {
    System.exit(0);
}

//显示菜单
public void showMenu(User user) {
    int choice;
    do {
        System.out.println("-------------------------欢迎使用中国建设银行ATM自助服务-------------------------");
        System.out.println("1.存款  2.取款  3.转账  4.查询余额  5.修改密码  6.修改预留手机号  7.注销账户  0.退出");
        System.out.println("------------------------------------------------------------------------------");
        System.out.print("请输入操作编码:");
        choice = input.nextInt();
        switch (choice) {
            case 1:
                this.deposit(user);
                break;
            case 2:
                this.withdraw(user);
                break;
            case 3:
                this.transfer(user);
                break;
            case 4:
                this.inquire(user);
                break;
            case 5:
                this.changePwd(user);
                break;
            case 6:
                this.changePhone(user);
                break;
            case 7:
                this.cancel(user);
                this.welcomeMenu();
                break;
            case 0:
                System.out.println("谢谢使用!");
                //结束该方法,执行该方法以下的语句
                this.welcomeMenu();
            default:
                System.out.println("输入有误!请重新输入!");
        }
    } while (true);
}

public void withdraw(User user) {
    System.out.print("请输入取款金额:");
    double money = input.nextDouble();
    if (money <= user.getBalance()) {
        user.setBalance(user.getBalance() - money);
        System.out.println("取款成功!当前余额为:" + user.getBalance() + "元!");
    } else {
        System.out.println("余额不足!");
    }
}

public void deposit(User user) {
    System.out.print("请输入存款金额:");
    double money = input.nextDouble();
    user.setBalance(user.getBalance() + money);
    System.out.println("存款成功!");
}

public void transfer(User user) {
    System.out.print("请输入卡号:");
    int no = input.nextInt();
    User check = transferCheck(no);
    if (check != null) {
        System.out.print("请输入转账金额:");
        Double money = input.nextDouble();
        if (user.getBalance() >= money) {
            user.setBalance(user.getBalance() - money);
            for (int i = 0; i < size; i++) {
                if (users[i].getCardNo() == no) {
                    users[i].setBalance(users[i].getBalance() + money);
                }
            }
            System.out.println("转账成功!");
        } else {
            System.out.println("余额不足!");
        }
    } else {
        System.out.println("输入的卡号有误!");
    }
}

public void inquire(User user) {
    System.out.println("账户余额为:" + user.getBalance() + "元!");
}

public void changePwd(User user) {
    String newPwd1;
    do {
        System.out.print("请输入8~16位新密码:");
        newPwd1 = input.next();
    } while (newPwd1.length() < 8 || newPwd1.length() > 16);
    System.out.print("请再次输入新密码:");
    String newPwd2 = input.next();
    if (newPwd1.equals(newPwd2)) {
        user.setPassWord(newPwd2);
        System.out.println("修改成功!");
    } else {
        System.out.println("两次密码输入不同!");
    }
}

public void changePhone(User user) {
    System.out.print("请输入正确的原预留手机号:");
    String oldPhone = input.next();
    if (oldPhone.equals(user.getPhone())) {
        String newPhone;
        do {
            System.out.print("请输入正确的新手机号:");
            newPhone = input.next();
        } while (newPhone.length() != 11);
        user.setPhone(newPhone);
        System.out.println("预留手机号修改成功!");
    } else {
        System.out.println("原预留手机号不正确!");
    }
}

public void cancel(User user) {![](https://img2020.cnblogs.com/blog/2205432/202011/2205432-20201119084849583-2032203194.png)


    int index = size + 1;
    for (int i = 0; i < size; i++) {
        if (users[i] != null) {
        if (users[i] == user) {
            index = i;
            break;
        }
    }
    }
    for (int i = index; i < size - 1; i++) {
        users[i] = users[i + 1];
    }
    size--;
    System.out.println("注销成功!");
}

}

运行结果:

psp2.1 任务内容 计划完成需要的时间(min) 实际完成需要的时间(min)
Planning 计划 60 120
Estimate 估计这个任务需要多少时间,并规划大致工作步骤 10 15
Development 开发 100 150
Analysis 需求分析(包括学习新技术) 12 20
Design Spec 生成设计文档 5 5
Design Review 设计复审 5 5
Coding Standard 代码规范 3 2
Design 具体设计 10 12
Coding 具体编码 60 85
Code Review 代码复审 5 6
Test 测试(自我测试,修改代码,提交修改) 10 15
Reporting 报告 9 6
Test Report 测试报告 3 2
Size Measurement 计算工作量 1 1
Postmortem & Process Improvement Plan 事后总结,并提出过程改进计划 4 10

posted on 2020-11-19 08:56  ???懵  阅读(103)  评论(0编辑  收藏  举报

导航