伊峰獨居

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            30 隨筆 :: 30 文章 :: 5 評論 :: 0 Trackbacks

          /**
          ?* @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;
          ?}

          }

          posted on 2006-08-25 13:50 伊峰 閱讀(101) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 阿鲁科尔沁旗| 滦平县| 德化县| 景洪市| 金沙县| 筠连县| 永登县| 五指山市| 彰化市| 承德市| 岑溪市| 大竹县| 乌鲁木齐县| 通榆县| 苍南县| 惠安县| 东丽区| 秀山| 威远县| 德兴市| 洮南市| 琼结县| 济阳县| 西和县| 宾阳县| 额济纳旗| 吐鲁番市| 许昌县| 志丹县| 克山县| 贞丰县| 伊金霍洛旗| 贡嘎县| 阿合奇县| 仪征市| 沛县| 石门县| 申扎县| 康马县| 海南省| 深圳市|