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

JAVA 模拟ATM柜员机模拟程序

提问网友 发布时间:2022-04-23 14:34
声明:本网页内容为用户发布,旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:1656858193@qq.com
4个回答
热心网友 回答时间:2023-06-25 02:09
/**
     要求:使用字符用户界面。当输入给定的卡号和密码(初始卡号和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:
    1、查询余额:初始余额为10000元
    2、ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。
    3、ATM存款:不能出现负存款。
    4、修改密码:新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。
    (卡号密码余额放到文件中)
 */
public class Test {
    private static int account;
    private static int password;
    private static int money;
    private static boolean isLogin;
    static{
        account = 123456;
        password = 123456;
        money = 10000;
        isLogin = false;
    }
    //存款
    public void cun(int cunKuan){
        if(cunKuan>=0){
            this.money += cunKuan;
        }else{
            System.out.println("存款不能为负!");
        }
    }
    //取款
    public void qu(int quKuan){
        if(this.money - quKuan < 0){
            System.out.println("余额不足!");
            return;
        }
        
        if(isValid(quKuan)){
            this.money -= quKuan;
        }else{
            System.out.println("取款不能为负,且应为100的倍数!");
        }
    }
    //判断是否为有效的金额
    private boolean isValid(int money){
        if(money >= 0 && money % 100 == 0){
            return true;
        }
        return false;
    }
    
    //登陆
    public void login(){
        System.out.println("请输入账号和密码【格式为:账号/密码】");
        String login = new Scanner(System.in).next();
        if(login.equalsIgnoreCase("123456/123456")){
            this.isLogin = true;
        }else{
            System.out.println("账号或者密码错误,请重新输入!");
            login();
        }
    }
    
    //主菜单
    public void show(){
        System.out.println("[1]存款");
        System.out.println("[2]取款");
        System.out.println("[3]退出");
        System.out.println("请输入:");
        int key = new Scanner(System.in).nextInt();
        switch (key) {
        case 1:
            cun(new Scanner(System.in).nextInt());
            break;
        case 2:
            qu(new Scanner(System.in).nextInt());
            break;
        case 3:
            System.exit(0);
        default:
            break;
        }
    }
    public static void main(String[] args) {
        Test t = new Test();
        t.login();
        if(t.isLogin){
            for(;;){
                t.show();
                System.out.println("您当前的余额为:" + t.money);
            }
        }
        
    }
}

热心网友 回答时间:2023-06-25 02:09
import java.util.*;
public class ATM {
static int people=123456;
static int mima=123456;
static int yue=10000;
static Scanner in=null;
public ATM(int people,int mima){
this.mima=mima;
}
public static void main(String[] args) {
chongxindenglu();
int count=1;
while(count!=0){
System.out.println("1、查询余额");
System.out.println("2、取款");
System.out.println("3、存款");
System.out.println("4、修改密码");
System.out.println("5、重新登录");
count=in.nextInt();
switch(count){
case 1: System.out.println(10000); System.out.println(); break;
case 2: quKuan(); break;
case 3: cunKuan(); break;
case 4: xiugai(); break;
case 5: chongxindenglu();
}
}
}
public static void quKuan(){
System.out.println("请输入取款金额:");
int qukuanjine=in.nextInt();
if(qukuanjine>5000){
System.out.println("取款金额不能大于5000"+"\n");
}else{
if(qukuanjine%100!=0){
System.out.println("取款金额必须为100的整数倍"+"\n");
}else{
yue=yue-qukuanjine;
System.out.println("您取出了"+qukuanjine+"元,您现在的余额为:"+yue+"元"+"\n");
}
}
}

public static void cunKuan(){
System.out.println("请输入存款金额");
int cunkuanjine=in.nextInt();
if(cunkuanjine<0){
System.out.println("存款金额不能小于0");
}else{
yue=yue+cunkuanjine;
System.out.println("您已成功存入:"+cunkuanjine+"元,您现在总余额为:"+yue+"元"+"\n");
}
}

public static void xiugai(){
System.out.println("请输入您的密码:");
int mima1=in.nextInt();
if(mima1==mima){
System.out.println("请输入新密码:");
mima=in.nextInt();
System.out.println("您的密码已修改为:"+mima+"\n");
}else{
System.out.println("密码输入错误:"+"\n");
}
}

public static void chongxindenglu(){
in=new Scanner(System.in);
System.out.println("请输入登录帐号:");
int denglupeople=in.nextInt();
System.out.println("请输入登录密码:");
int denglumima=in.nextInt();

if(denglupeople==people && denglumima==mima)
System.out.println("帐号登录成功"+"\n");
else
System.out.println("密码输入错误,登录失败"+"\n");
}

}
热心网友 回答时间:2023-06-25 02:10
/*
要求:使用字符用户界面。当输入给定的卡号和密码(初始卡号和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:
1、查询余额:初始余额为10000元
2、ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。
3、ATM存款:不能出现负存款。
4、修改密码:新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。
(卡号密码余额放到文件中)
*/
publicclassATM{
privateAccountacc;
privateFiledataFile;
privateFileWriterfw;
privateBufferedWriterbw;
privateStringfilePath="./data.txt";
publicATM(){
this.acc=newAccount();
try{
this.dataFile=newFile(this.filePath);
if(!this.dataFile.exists()){
this.dataFile.createNewFile();
}
this.fw=newFileWriter(this.filePath);
this.bw=newBufferedWriter(this.fw);
}catch(IOExceptionio){
System.err.println("Cannotopenfile");
io.printStackTrace();
}catch(Exceptione){
e.printStackTrace();
}
}
publicstaticvoidmain(String[]args){
newATM().interact();
}
publicvoidinteract(){
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Account#:");
Stringtemp=br.readLine();
System.out.println("Password:");
Stringtemp2=br.readLine();
if(!this.acc.isValid(Long.parseLong(temp.trim()),temp2.trim()){
System.err.println("Wrongpassword");
return;
}
System.out.println("1.AccountInquery.");
System.out.println("2.Withdraw");
System.out.println("3.Deposit.");
System.out.println("4.ChangePassword.");
System.out.println("5.ExporttoFile.");
System.out.println("0.Exit.");
intc=100;
while(c!=0){
Stringstr=br.readLine();
try{
intc=Integer.parseInt(str.trim());
}catch(NumberFormatExceptionnfe){
System.err.println("Invalidchoice");
continue;
}
switch(c){
case0:
System.out.println("Thankyou");
break;
case1:
System.out.println("Balance:"+this.acc.balanceInquery());
break;
case2:
System.out.println("Howmuch?");
Stringtemp=br.readLine();
try{
longammount=Long.parseLong(temp.trim());
this.acc.withdraw(ammount);
break;
}catch(NumberFormatExceptionnfe){
System.err.println("Invalidamount");
continue;
}
case3:
System.out.println("Howmuch?");
Stringtemp=br.readLine();
try{
longammount=Long.parseLong(temp.trim());
this.acc.deposit(ammount);
break;
}catch(NumberFormatExceptionnfe){
System.err.println("Invalidamount");
continue;
}
case4:
System.out.println("Oldpassword:");
Stringtemp=br.readLine();
System.out.println("Newpassword:");
Stringtemp2=br.readLine();
this.acc.changePassword(temp,temp2);
break;
case5:
this.bw.write(this.acc.toString());
break;
default:
break;
}
}
}
}
classAccount{
privatelongaccNo=123456;
privateStringpass="123456";
privatelongbalance=10000;
publicAccount(){
}
publicbooleanisValid(longaccNo,Stringpass){
return(this.accNo==accNo)&&(pass.equals(this.pass));
}
publicvoidchangePassword(StringoldPass,Stringpassword){
if(!oldPass.equals(this.pass)){
System.err.println("Wrongpassword.");
return;
}
if(password.length<6){
System.err.println("Passwordtooshort");
return;
}
if(password.equals(this.pass)){
System.err.println("Passwordcannotbethesame.");
return;
}
this.pass=password;
}
publiclongbalanceInquery(){
returnthis.balance;
}
publicvoidwithdraw(longamount){
if(amount>5000||amount<0){
System.err.println("Withdrawlimit:$0-$5000");
return;
}
if((amount%100)!=0){
System.err.println("Theamounthastobeaproctof100");
return;
}
longnewBalance=this.balance-amount;
if(newBalance<0){
System.err.println("Notenoughmoneyintheaccount");
return;
}
this.balance=newBalance;
}
publicvoiddeposit(longamount){
if(amount<0){
System.err.println("Cannotdepositnegativeamount");
return;
}
this.balance+=amount;
}
publicStringtoString(){
return("Account#:"+this.accNo+"\n"+"Password:"+this.pass+"\n"+"Balance:"+this.balance);
}
}
热心网友 回答时间:2023-06-25 02:10
/*
要求:使用字符用户界面。当输入给定的卡号和密码(初始卡号和密码为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);
}
}

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

用C语言一个ATM取款机的程序代码(用循环语句) 就是用JAVA编写一个ATM的程序 在C语言中ATM自动取款机的功能程序怎么写啊? 用c++来做一个ATM的程序 用C#编写一个自动取款机(ATM)模拟程序 什么是ATM系统 ATM自动取款机的使用程序 ATM模拟程序 银行卡atm 取款程序 用c++编写ATM程序 ATM机取款的操作程序是怎样的。 ATM取款机程序 这种行李箱的锁坏了可以修吗? 行李箱的密码锁坏了可以换新的吗? 旅行箱密码忘记,锁坏了,还可以换一个吗?? 行李箱密码锁坏了怎么办可不可以换哎 我的行李箱的嗯锁扣坏了能换一个不? 我密码箱锁坏了,能换新的吗 windows10 中文输入法只能输入一个字母,不管哪种中文输入法都是这样,英... win10输入法的问题,不能打汉字,只能打字母? 怎样用JAVA编写一个ATM简单的应用程序 用C++模拟ATM柜员机程序 只狼这个,一直说要去那柿子,我背包里的这个不是吗?为什么不能给他 只狼游戏里有了鲜柿子干柿子的话,要给谁?? 老哥们只狼怎么才能触发她要柿子的那个剧情啊? 《只狼》鲜柿子在哪? 只狼鲜柿子干柿子有什么用? 只狼干柿子和鲜柿子有什么用? 飞雪玉花的歌词 飞雪玉花歌词 只狼有没有大佬刷出来过柿子?我现在柿子不够了,贼急! 《秦时明月》的插曲《飞雪玉花》的歌词? 在只狼里干柿子到底是要怎么拿啊? 求秦时明月的插曲《飞雪玉花》(人唱版)的歌词?急!速! 游戏只狼普通柿子在哪? 跪求秦时明月飞雪玉花的全部词?就是带上金戈铁马笑谈间后面两段的,要时间,精确到秒的。 《只狼》达成龙之归乡的结局有哪些条件? 高自由度《只狼》世界中,怎样获得冰泪? 秦时明月 所有的人物角色歌歌词 一舞倾明月的歌词
Top