问答1 问答5 问答50 问答500 问答1000
网友互助专业问答平台

ATM模拟程序

提问网友 发布时间:2022-04-23 14:34
声明:本网页内容为用户发布,旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:1656858193@qq.com
2个回答
热心网友 回答时间:2023-08-08 17:54
/*
要求:使用字符用户界面。当输入给定的卡号和密码(初始卡号和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:
1、查询余额:初始余额为10000元
2、ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。
3、ATM存款:不能出现负存款。
4、修改密码:新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。
(卡号密码余额放到文件中)
*/

public class ATM {

private Account acc;

private File dataFile;
private FileWriter fw;
private BufferedWriter bw;

private String filePath = "./data.txt";

public ATM() {
this.acc = new Account();
try {
this.dataFile = new File(this.filePath);
if (!this.dataFile.exists()) {
this.dataFile.createNewFile();
}
this.fw = new FileWriter(this.filePath);
this.bw = new BufferedWriter(this.fw);
} catch (IOException io) {
System.err.println("Cannot open file");
io.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
new ATM().interact();
}

public void interact() {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Account #: ");
String temp = br.readLine();
System.out.println("Password: ");
String temp2 = br.readLine();
if (!this.acc.isValid(Long.parseLong(temp.trim()), temp2.trim()) {
System.err.println("Wrong password");
return;
}
System.out.println("1. Account Inquery.");
System.out.println("2. Withdraw");
System.out.println("3. Deposit.");
System.out.println("4. Change Password.");
System.out.println("5. Export to File.");
System.out.println("0. Exit.");
int c = 100;
while (c != 0) {
String str = br.readLine();
try {
int c = Integer.parseInt(str.trim());
} catch (NumberFormatException nfe) {
System.err.println("Invalid choice");
continue;
}
switch (c) {
case 0:
System.out.println("Thank you");
break;
case 1:
System.out.println("Balance: " + this.acc.balanceInquery());
break;
case 2:
System.out.println("How much? ");
String temp = br.readLine();
try {
long ammount = Long.parseLong(temp.trim());
this.acc.withdraw(ammount);
break;
} catch (NumberFormatException nfe) {
System.err.println("Invalid amount");
continue;
}
case 3:
System.out.println("How much? ");
String temp = br.readLine();
try {
long ammount = Long.parseLong(temp.trim());
this.acc.deposit(ammount);
break;
} catch (NumberFormatException nfe) {
System.err.println("Invalid amount");
continue;
}
case 4:
System.out.println("Old password: ");
String temp = br.readLine();
System.out.println("New password: ");
String temp2 = br.readLine();
this.acc.changePassword(temp, temp2);
break;
case 5:
this.bw.write(this.acc.toString());
break;
default:
break;
}
}
}

}

class Account {

private long accNo = 123456;
private String pass = "123456";
private long balance = 10000;

public Account() {

}

public boolean isValid(long accNo, String pass) {
return (this.accNo == accNo) && (pass.equals(this.pass));
}

public void changePassword(String oldPass, String password) {
if (!oldPass.equals(this.pass)) {
System.err.println("Wrong password.");
return;
}
if (password.length < 6) {
System.err.println("Password too short");
return;
}
if (password.equals(this.pass)) {
System.err.println("Password cannot be the same.");
return;
}
this.pass = password;
}

public long balanceInquery() {
return this.balance;
}

public void withdraw(long amount) {
if (amount > 5000 || amount < 0) {
System.err.println("Withdraw limit: $0-$5000");
return;
}
if ((amount % 100) != 0) {
System.err.println("The amount has to be a proct of 100");
return;
}
long newBalance = this.balance - amount;
if (newBalance < 0) {
System.err.println("Not enough money in the account");
return;
}
this.balance = newBalance;
}

public void deposit(long amount) {
if (amount < 0) {
System.err.println("Cannot deposit negative amount");
return;
}
this.balance += amount;
}

public String toString() {
return ("Account #: " + this.accNo + "\n" + "Password: " + this.pass + "\n" + "Balance: " + this.balance);
}
}
请采纳答案,支持我一下。
热心网友 回答时间:2023-08-08 17:54
我有一个ATM模拟系统安装程序链接: https://pan.baidu.com/s/1au6ihRBQXKyRnFPdJTUk4w 密码: t9yw

本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。

银行卡atm 取款程序 用c++编写ATM程序 ATM机取款的操作程序是怎样的。 ATM取款机程序 这种行李箱的锁坏了可以修吗? 行李箱的密码锁坏了可以换新的吗? 旅行箱密码忘记,锁坏了,还可以换一个吗?? 行李箱密码锁坏了怎么办可不可以换哎 我的行李箱的嗯锁扣坏了能换一个不? 我密码箱锁坏了,能换新的吗 windows10 中文输入法只能输入一个字母,不管哪种中文输入法都是这样,英... win10输入法的问题,不能打汉字,只能打字母? 键盘出现打不出汉字,打出来的全是字母,怎么处理? win10中文打字只显示字母怎么办? 大神求教,明基卓威ec1-a鼠标,右侧会透光么?是不是有问题啊?? 卓威为什么不出2k 240或144的屏幕? 克拉玛依独山子区机动车辆检测有限责任公司怎么样? 明基XL2430显示器怎么样 克拉玛依独山子查核酸怎么查? 明基卓威xl2540和戴尔s2417dg哪个显示器好 ATM自动取款机的使用程序 什么是ATM系统 用C#编写一个自动取款机(ATM)模拟程序 用c++来做一个ATM的程序 在C语言中ATM自动取款机的功能程序怎么写啊? 就是用JAVA编写一个ATM的程序 用C语言一个ATM取款机的程序代码(用循环语句) JAVA 模拟ATM柜员机模拟程序 怎样用JAVA编写一个ATM简单的应用程序 用C++模拟ATM柜员机程序 只狼这个,一直说要去那柿子,我背包里的这个不是吗?为什么不能给他 只狼游戏里有了鲜柿子干柿子的话,要给谁?? 老哥们只狼怎么才能触发她要柿子的那个剧情啊? 《只狼》鲜柿子在哪? 只狼鲜柿子干柿子有什么用? 只狼干柿子和鲜柿子有什么用? 飞雪玉花的歌词 飞雪玉花歌词 只狼有没有大佬刷出来过柿子?我现在柿子不够了,贼急! 《秦时明月》的插曲《飞雪玉花》的歌词?
Top