伊峰独居

  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 伊峰 阅读(95) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: