?? class_back.java
字號:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class class_back {
/**
* @param args
*/
static float xx = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Back_Serve back = new Back_Serve(500);
getMoney();
back.set_GetMoeny(xx);
try {
back.Withdrawal();
} catch (ErrorPrint e) {
//e.printStackTrace();
e.printfError();
}
}
public static void getMoney(){
System.out.print("請輸入取款錢數:");
try {
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
String cinx = cin.readLine();
xx = Float.parseFloat(cinx);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class Back_Serve{
private float Back_MoneyTotal ;
private float putMoney ;
private float getMoeny ;
Back_Serve(){
this.Back_MoneyTotal = 0 ;
}
Back_Serve(float MoneyTotal){
this.Back_MoneyTotal = MoneyTotal ;
}
public void set_PutMoeny(float money){
this.putMoney = money ;
}
public void set_GetMoeny(float money){
this.getMoeny = money ;
}
public float Personal_Back_MoneyTotal(){
return this.Back_MoneyTotal ;
}
public float Persional_Get_MoneyTotal(){
return this.getMoeny ;
}
public void Withdrawal()throws ErrorPrint{
if(Persional_Get_MoneyTotal() > Personal_Back_MoneyTotal()){
throw new ErrorPrint();
}else{
this.Back_MoneyTotal = this.Personal_Back_MoneyTotal() - this.Persional_Get_MoneyTotal() ;
System.out.println("取款金額為:" + this.Persional_Get_MoneyTotal());
System.out.println("銀行剩余錢數:" + this.Personal_Back_MoneyTotal());
}
}
}
class ErrorPrint extends Exception{
//自定義的異常處理類
ErrorPrint(){}
public void printfError() {
System.out.println("對不起,銀行當前總錢數無法滿足您的要求,請稍候在取款,謝謝合作!!");
System.exit(1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -