肿瘤康复网,内容丰富有趣,生活中的好帮手!
肿瘤康复网 > java系统系统异常处理 银行系统(Java)异常处理

java系统系统异常处理 银行系统(Java)异常处理

时间:2024-07-11 18:05:52

相关推荐

package analog_ATM;

import java.io.IOException;

//import java.sql.*;

import java.util.*;

/**

* 1.账户类,模拟ATM机,即读取了用户的个人信息

* 2.查询余额

* 3.交易记录

* 4.存/取

* 5.其他功能

*/

class InsufficientFundsException extends Exception{//自定义异常类

Account account; //貌似有危险

private double dAmount;

InsufficientFundsException(){} //无参

InsufficientFundsException(Account account, double dAmount){

this.account = account;

this.dAmount = dAmount;

}

public String getMessage(){ //错误信息

String str = "取款失败!账户余额:" + account.getBalance()+ ",取款额:" + dAmount + ",余额不足";

return str;

}

}

class Account{

boolean isUseful = true; //卡是否可用

String cardNumber; //4位数的卡号,由银行按照规定分配

String userName; //用户名

String password; //密码

double balance; //余额

Account(){

this.isUseful = true;

this.balance = 0.0;

}

Account(String cardNumber, String userName, String password){

this.isUseful = true;

this.balance = 0.0;

this.cardNumber = cardNumber;

this.userName = userName;

this.password = password;

}

//

//public void setCardNumber() {

//Random rnd = new Random();

//rnd.setSeed(9999);

//}

//

public void setUserName() throws IOException{//cin exception

Scanner sc = new Scanner(System.in);

System.out.println("请输入您的用户名:");

this.userName = sc.nextLine();

}

//

public void setPassword() throws IOException {//cin exception

Scanner sc = new Scanner(System.in);

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

this.password = sc.nextLine();

}

//查余额

public double getBalance(){

return this.balance;

}

//取

public void withdraw(double money) throws InsufficientFundsException{

if (balance < money) {

throw new InsufficientFundsException(this, money);

}

balance = balance - money;

System.out.println("取款成功!账户余额为" + balance);

}

//查记录

public void recordsInfo() {

}

//存

public void saveMoney(double money) {

this.balance += money;

System.out.println("存款成功!新余额为:"+this.balance);

}

}

//银行系统

class Bank{

Account card[];

static int current_account_index = 0;

static int accountNumber = 0; //账户数量

static int illegalCardNumber = 0; //冻结数量

Bank(){

card = new Account[1];

card[0] = new Account("1000", "root", "password");

accountNumber ++;

}

void addAccount() throws IOException, InsufficientFundsException {

Account [] temp = card;

card = new Account[accountNumber + 1];

for(int i = 0; i

如果觉得《java系统系统异常处理 银行系统(Java)异常处理》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。