/**
?* @author DREAM GUO
?*
?*/
public class BankAccount {
?private String cName; // 帳戶名
?private long cAccountNO; // 帳號
?private double cBalance; // 余額
?private String[] cRecord = new String[10]; // 此數組用于記錄操作
?private int record_size; // 操作次數
?/**
? * @param ba
? *??????????? 帳戶
? * @return 查詢結果(字符串)
? */
?static String CheckAccount(BankAccount ba) {
??String res;
??res = "================以下內容為查詢結果================\n" + "客戶姓名:"
????+ ba.cName + " 帳號:" + Long.toString(ba.cAccountNO) + " 帳戶余額:"
????+ ba.cBalance + "\n\n" + "[存取款操作記錄]";
??for (int i = 0; i < ba.record_size; i++) {
???res += "\n" + (i + 1) + ": " + ba.cRecord[i];
??}
??return res;
?}
?/**
? * @param name
? *??????????? 客戶姓名
? * @param accountNO
? *??????????? 賬戶編號
? * @param balance
? *??????????? 余額(大于10.00美元)
? */
?public BankAccount(String name, long accountNO, double balance) {
??this.cRecord[0] = "無操作記錄";
??this.record_size = 0;
??if (balance < 10) {
???System.out
?????.println("Warning: The custmoer's balance must over $10.00 .");
???return;
??}
??this.cName = name;
??this.cAccountNO = accountNO;
??this.cBalance = balance;
??System.out.println("Create a Bank account for " + name
????+ ", account number is " + accountNO + ", balance is $"
????+ balance + ".");
?}
?/**
? * @param amount
? *??????????? 存款金額
? */
?public void deposite(double amount) { // 存錢
??if (amount > 0.00) {
???this.cBalance += amount;
???this.write("Deposite into account " + amount + " dollars");
???System.out.println("Deposite into account " + amount + " dollars.");
??} else {
???System.out.println("Warning: The amount must over $0.00 .");
??}
?}
?/**
? * @param amount
? *??????????? 取款金額
? * @return (1)-1 異常 (2)amount 取款正常 (3)0 余額不足
? */
?public double withdraw(double amount) { // 取錢, 如帳戶余額大于等于所取款額,返回amount,
??// 否則,返回0
??double balance = this.getBalance();
??if (amount <= this.cBalance) {
???this.cBalance -= amount;
???System.out.println(this.cName + " try to withdarw " + amount
?????+ " dollars from the account,"
?????+ " the withdraw is permitted.");
???this.write(this.cName + " try to withdarw " + amount
?????+ " dollars from the account,"
?????+ " the withdraw is permitted.");
???return amount;
??} else if (amount > this.cBalance) {
???System.out.println(this.cName + " try to withdarw " + amount
?????+ " dollars from the account,"
?????+ " he withdraw is denied due to inadequate balance.");
???return 0;
??}
??this.cBalance = balance;
??return -1;
?}
?public double getBalance() {
??return this.cBalance;
?}
?// 活期儲蓄利率
?/**
? * @param i
? *??????????? 利率
? * @param b
? *??????????? 余額
? * @param t
? *??????????? 期限
? * @return 連本帶息余額
? */
?static double CountInterest(double i, double b, int t) {
??double res = b;
??for (int n = 0; n < t; n++) {
???res = res * (1 + i);
??}
??res = Math.round(res * 100) / 100.00;
??return res;
?}
?private void write(String s) {
??if (this.record_size >= this.cRecord.length) {
???String temp[] = this.cRecord;
???this.cRecord = new String[this.record_size + 10];
???for (int i = 0; i < this.record_size; i++) {
????this.cRecord[i] = temp[i];
???}
??}
??this.cRecord[this.record_size++] = s;
?}
}