博客班级 | 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(" 1、开户
2、登录
0、退出
");
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(" 1、取款
2、存款
3、查询余额
4、转账
5、修改密码
6、销户
7、重新登录");
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实现图形化。