java编写atm机,java编写简单的ATM存取系统

package cn.Atm;

/**

* @author 偶my耶

*/

import java.io.*;

import com.project.project;

public class ATM {

Account act;

public ATM(){

act=new Account("0000", "test", "0000", 2000);

}

/*************欢迎界面*********************/

protected void Welcome(){

String str="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

System.out.print(str+"\n");

System.out.print(

"1.取款"+"\n"+

"2.查询"+"\n"+

"3.存款"+"\n"+

"4.退出"+"\n"

);

System.out.print(str+"\n");

}

/************登陆系统********************/

protected void Load_Sys() throws Exception{

String card,pwd;

int counter=0;

BufferedReader  br=new BufferedReader(new InputStreamReader(System.in));

do{

System.out.println("请输入你的卡号");

card=br.readLine();

System.out.println("请输入你的密码");

pwd=br.readLine();

if (!isRight(card,pwd)) {

System.out.println("你的卡号或密码有误");

counter++;

}

else {

Welcome();

SysOpter();

}

}while(counter<5);

System.exit(1);

}

/**********系统操作提示******************/

protected void SysOpter() throws Exception {

int num;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("请选择你要操作的项目(1--4)");

num=br.read();

switch (num) {

case 49:

GetBalance();

break;

case 50:

Inqu_Iofo();

break;

case 51:

AddBalance();

break;

case 52:

Exit_Sys();

break;

}

}

/**********信息查询*******************/

protected void Inqu_Iofo() throws Exception{

// TODO Auto-generated method stub

String str="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

System.out.print(str+"\n");

System.out.print(

"账号"+act.getNumber()+"\n"+

"姓名"+act.getName()+"\n"+

"余额"+act.getMoney()+"\n"+

str+"\n"

);

SysOpter();

}

/**********存款******************/

public void AddBalance() throws Exception{

// TODO Auto-generated method stub

String str=null,str1;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

do {

System.out.println("请输入存款数目");

str=br.readLine();

double qu=Double.valueOf(str).doubleValue();

act.add_Balancen(qu);

System.out.println("存款成功,你的账户余额为"+act.getMoney());

Welcome();

SysOpter();

} while (true);

}

/**********取款********************/

public void GetBalance() throws Exception{

// TODO Auto-generated method stub

String str=null,str1;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

do {

System.out.println("请输入取款数目");

str=br.readLine();

double qu=Double.valueOf(str).doubleValue();

if(qu>act.getMoney()){

System.out.println("余额不足请重新输入");

}

else {

act.sub_Balance(qu);

System.out.println("取款成功你的账户余额未"+act.getMoney());

Welcome();

SysOpter();

}

} while (true);

}

/*********退出******************/

protected void Exit_Sys () {

// TODO Auto-generated method stub

System.out.println("安全退出!");

System.exit(1);

}

/**********卡号和密码是否正确********************/

protected boolean isRight (String card, String pwd) {

// TODO Auto-generated method stub

if (act.getNumber().equals(card)&&act.getPassword().equals(pwd)) {

return true;

} else {

return false;

}

}

public static void main(String[] args) throws Exception {

ATM atm=new ATM();

//        atm.Welcome();

atm.Load_Sys();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值