日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

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

發布時間:2023/12/15 windows 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java系统系统异常处理,银行系统(Java)异常处理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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)异常处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。