/**
*具体实现取款功能
*/
import java.util.*;
import java.io.*;
class ATM{
Acount act;
public ATM(){
act=new Acount("111111","大卫","012345",50000);
}
/*********欢迎界面***********/
public void welcome(){
String str="------------";
System.out.println(str+"欢迎使用模拟自动取款机程序"+str);
System.out.println("1.取款"+"\n"+
"2.查询信息"+"\n"+
"3.密码设置"+"\n"+
"4.存钱"+"\n"+
"5.退出系统");
}
/******登入系统********/
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
{
SysOpert();
}
}while(counter<3);
lockSys();
}
/********系统操作***********/
protected void SysOpert()throws Exception{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请选择您要操作的项目(1-4)");
num=br.read();//num为ASICC码转换的整数
switch(num){
case 49:BetBalance();break;
case 50:Inqu_info();break;
case 51:Set_password();break;
case 52:deposit();break;
case 53:lockSys();break;
}
System.exit(1);
}
/***********取款**************/
public void BetBalance()throws Exception{
double a=0.0,b;
Scanner br=new Scanner(System.in);
do{
System.out.println("请输入您要取得金额数目:");
a=br.nextDouble();
b=act.getMoney();
if(a-b>0){
System.out.println("超过已有金额,请重新输入金额数目:");
}
else
{
/*操作成功*/
act.setMoney(a);
System.out.println("取款成功,请收好您的钱");
welcome();
SysOpert();
}
}while(true);
}
/************信息查询***************/
protected void Inqu_info()throws Exception{
System.out.println("-------------------------"+"\n"+
"账号:"+act.getCode()+"\n"+
"姓名:"+act.getName()+"\n"+
"金钱:"+act.getMoney()+"\n"+
"---------------------------------");
welcome();
SysOpert();
}
/***************判断卡内是否有钱****************/
protected boolean isBalance(){
if(act.getMoney()>=0)
{
return true;
}
else
{
System.out.println("对不起,您的钱数不够胡卡已透支");
return false;
}
}
/***************判断卡号是否正确**********************/
protected boolean isRight(String card,String pwd){
if(act.getCode().equals(card)&&act.getPassword().equals(pwd))
{
return true;
}
else
return false;
}
/******************密码修改*********************/
protected void Set_password()throws Exception{
String pwd=null,pwd1,pwd2;
int counter=0;
Scanner br=new Scanner(System.in);
do{
System.out.println("请输入旧密码:");
pwd=br.next();
if(act.getPassword().equals(pwd))
{
do{
System.out.println("请输入新密码:");
pwd1=br.next();
System.out.println("请再次输入新密码:");
pwd2=br.next();
if(pwd1.equals(pwd2))
{
act.setPassword(pwd1);
System.out.println("修改密码成功!请使用新密码");
welcome();
load_sys();
break;
}
else
{
System.out.println("两次密码输入不相同");
}
}while(true);
}
else
{
counter++;
System.out.println("密码输入错误"+counter+"次,请重新输入");
}
}while(counter<3);
lockSys();
}
/**************锁定机器********************/
protected void lockSys(){
System.out.println("感谢您使用本系统,欢迎您下次再来,再见!");
System.exit(1);
}
/*******************存钱操作*************************/
protected void deposit()throws Exception{
double num=0.0;
Scanner br=new Scanner(System.in);
System.out.println("请输入存入金额数目:");
num=br.nextDouble();
act.setMoneyDeposit(num);
welcome();
SysOpert();
}
}