模拟银行系统的java程序

我这里有一段模拟银行系统的java程序,我前几天在网上看到的句拿来看看,这里面有几个问题我搞好了几个,还有两个比较严重没搞好,
一、本系统中有一个严重的bug就是不管有钱没钱我都能从里面随意取出钱,这主要是double和String比较时的问题有问题的代码是:
double str = 0 ;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入您要取的数目:");
String s=String.valueOf(str);
s=br.readLine();
if(str>act.get_Money()) {//这里str总是0.0所以总是执行else语句
System.out.println(act.get_Money());
System.out.println("超过已有的钱数,请重新输入您要取的数目:");
SysOpter();
下面我把所有的代码贴出来大家看一下,如果能解决的话告诉我,我将不胜感激!!

package test;


import java.io.*;

/*该类为实现客户信息及部分功能*/
public class Account {
private String code =null; //信用卡号
private String name =null; //客户姓名
private String password=null; //客户密码
private double money =0.0; //卡里金额

/********************/
public Account(String code,String name,String password,double money)
{
this.code=code;
this.name=name;
this.password=password;
this.money=money;

}
public static void main(String[] args) throws Exception
{
ATM atm=new ATM();
atm.Welcome();
atm.Load_Sys();
atm.Exit_Sys();
}
protected String get_Code() {
return code;
}

protected String get_Name() {
return name;
}

protected String get_Password() {
return password;
}

public double get_Money() {
return money;
}

/*得到剩余的钱的数目*/
protected void set_Balance(double mon) {
money -= mon;
}
}

/**********实现具体取款机功能*********/
class ATM {
Account act;
// private String name;
// private String pwd;

public ATM() {
act=new Account("317337581","Devil","123456",500000);
}

/***********欢迎界面***********/
protected void Welcome()
{
String str="---------------------------------";
System.out.print(str+"\n"+
"欢迎使用sbr模拟自动取款机程序.\n"+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
SysOpter();

}while(counter<3);
Lock_Sys();
}

/**********系统操作**********/
protected void SysOpter() throws Exception
{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请选择您要操作的种类:");
System.out.print(" 1.>取款."+"\n"+
" 2.>查询信息."+"\n"+
" 3.>密码设置."+"\n"+
" 4.>退出系统."+"\n");
num=br.read(); //num为ASICC码转换的整数
switch(num) {
case 49: BetBalance(); break;
case 50: Inqu_Info(); break;
case 51: Set_Password(); break;
case 52: Exit_Sys(); break;
}
System.exit(1);
}

/**********信息查询
* @throws Exception **********/
protected void Inqu_Info() throws Exception {
System.out.print("---------------------\n"+
act.get_Code()+"\n"+
//act.get_Name()+"\n"+
act.get_Money()+"\n"+
"-----------------------\n");
System.out.println("请选择操作:");
SysOpter();
}

/**********取款**********/
public void BetBalance() throws Exception
{
double str = 0 ;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入您要取的数目:");
String s=String.valueOf(str);
s=br.readLine();
if(str>act.get_Money()) {
System.out.println(act.get_Money());
System.out.println("超过已有的钱数,请重新输入您要取的数目:");
SysOpter();
}
else {
/*操作成功*/
// act.set_Balance(str);
System.out.println("取款成功,请收好您的钱.");
Welcome();
SysOpter();
}

}


/**********判断卡内是否有钱**********/
protected boolean isBalance() {
if(act.get_Money()<0) {
System.out.println("对不起,您的钱数不够或卡已透支.");
return false;
}
return true;
}

/********卡号密码是否正确******/
protected boolean isRight(String card,String pwd)
{
if(act.get_Code().equals(card) && act.get_Password().equals(pwd))
return true;
else
return false;
}

/**********密码修改**********/
protected void Set_Password() throws Exception
{
String pwd=null;
int counter=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("请输入旧密码:");
pwd=br.readLine();
if(act.get_Password().equals(pwd))
{
do {
System.out.println("请输入新密码:");
String pwd1=br.readLine();
System.out.println("请再次输入新密码:");
String pwd2=br.readLine();
if(!pwd1.equals(pwd2))
{
System.out.println("两次输入不一致,请再次输入.");
}
else
{
System.out.println("密码修改成功,请使用新密码.");
Welcome();
SysOpter();
}
}while(true);
}
else{
for(int i=0;i<2;i++){
int j=2;
for(;j>0;j--){


System.out.println("密码输入错误!");
System.out.println("再输入"+j+"次卡将被锁定");
pwd=br.readLine();
if(j==1){
System.out.println("您的卡被锁定请和本行联系!");
return;
}
}
if(act.get_Password().equals(pwd)){
do {
System.out.println("请输入新密码:");
String pwd1=br.readLine();
System.out.println("请再次输入新密码:");
String pwd2=br.readLine();
if(!pwd1.equals(pwd2))
{
System.out.println("两次输入不一致,请再次输入.");
}
else
{
System.out.println("密码修改成功,请使用新密码.");
Welcome();
SysOpter();
}
}while(true);
}
}
System.out.println("您的卡被锁定请和本行联系!");
}
}while(counter>3);

}

/**********锁定机器**********/
protected void Lock_Sys() {
System.out.println("对不起,您的操作有误,卡已被没收.");
System.exit(1);
}

/**********结束系统**********/
protected void Exit_Sys() {
System.out.println("感谢您使用本系统,欢迎下次再来,再见!");
System.exit(1);

}

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值