import java.util.Scanner;
class BankAccount {
private String name;
private int money,type;
/**
* 新建一個帳戶
*/
void createAccount (int type , int count , String name) {
this.name = name;
this.money = count;
this.type = type;
System.out.println("帳戶開戶完成");
}
/**
* 存入金錢
*/
void creditAccount (int count) {
if (money < 0) {
System.out.println("存入金額小於零,無效");
return;
}
this.money += calculateInterest(count);
System.out.printf("已存入%d,目前帳戶餘額%d\n",count,getCurrentBalance());
}
/**
* 領取金錢
*/
void debitAccount (int count) {
if ((count - this.money) > 0 && type == 1) {
System.out.println("不好意思,您所領取的金額超出帳戶裡的剩餘金額");
return;
}
this.money -= count;
System.out.printf("已領取%d,目前帳戶餘額%d\n",count,getCurrentBalance());
}
/**
* 計算手續費
*/
int calculateInterest (int count) {
if (this.type == 1) {
return count -= 100;
}
return count;
}
/**
* 取得目前帳戶餘額
*/
int getCurrentBalance() {
return this.money;
}
}
public class test {
public static void main (String[] ymc) {
BankAccount bank = new BankAccount();
Scanner in = new Scanner(System.in);
System.out.println("請輸入您的姓名");
String name = in.next();
System.out.println("請輸入所要創立的帳戶等級 1.一般帳號\t2.白金帳號");
int type = in.nextInt();
System.out.println("請輸入所要創立的帳戶等級第一筆金額");
int count = in.nextInt();
int chooice,money;
bank.createAccount(type, count, name);
do {
System.out.println("請選擇服務項目");
System.out.println("1.存錢");
System.out.println("2.領錢");
System.out.println("3.離開");
chooice = in.nextInt();
if ( chooice == 1 ) {
System.out.println("請輸入欲存入金額");
money = in.nextInt();
bank.creditAccount(money);
} else if ( chooice == 2 ) {
System.out.println("請輸入欲領取金額");
money = in.nextInt();
bank.debitAccount(money);
}
} while (chooice != 3); {
System.out.println("感謝您的光臨");
}
}
}