黑马程序员技术交流社区

标题: 简单ATM 模拟 [打印本页]

作者: 海带    时间: 2015-4-11 23:19
标题: 简单ATM 模拟
本帖最后由 海带 于 2015-4-13 00:10 编辑

设计一新的Account类需求:
1 添加一个Stirng 类型的新数据域name来存储客户的名字。
2 添加一个新的构造方法,改方法创建一个带指定名字,id 和收支额的账户。
3 添加一名为Transaction的新数据域,他是ArrayList类型的。可以为账户存储交易。每个交易都是一个Transaction的一个实例
4修改withDraw和deposit的方法,向Transaction数组线性表添加一笔交易。
5 创建一个年利率为1.5%,收支额为1000,ID为1122,名字为张三的Account.先存入30,40和50元,再取出5,8,和12元、打印账户清单;
显示账户名字,利率,收支额和所有交易。
Account
  1. import java.util.Date;

  2. public class Account {
  3.         private int id = 0;
  4.         private double  balance = 0;//收支额
  5.         private  static double annualInterestRate = 0;//利率
  6.         private Date dateCreated ;
  7.         public Account(){
  8.                 Date dateCreated = new Date();
  9.         }
  10.         public Account(int id,double balance){//构造方法
  11.                 this.id = id;
  12.                 this.balance = balance;
  13.                
  14.         }
  15.         public int getId(){
  16.                 return id;
  17.         }
  18.         public void setId(int id ){
  19.                 this.id = id;
  20.         }
  21.         public double getBalance(){
  22.                
  23.                 return balance;
  24.         }
  25.         public void setBalance(double balance){
  26.                 this.balance = balance;
  27.         }
  28.         public double getAnnualInterstRAte(){
  29.                 return annualInterestRate;
  30.         }
  31.         public void setAnnulInterestRate(double annualInterestRate){
  32.                 this.annualInterestRate = annualInterestRate;
  33.         }
  34.         public Date getDate(){
  35.                 Date dateCreated = new Date();
  36.                 return dateCreated;
  37.         }
  38.         public double getMonthlyInterestRate(){
  39.                 return this.annualInterestRate / 12;
  40.         }
  41.         public double getwithDraw(double n){
  42.                 return   balance = balance - n;
  43.         }
  44.         public double depoist(double n){
  45.                 return  balance = balance + n;
  46.         }

  47. }
复制代码
Transaction类的uml图;
      Transaction
---------------------------------
-date: java.util.Date                     这笔交易的日期
-type :char                                 交易的类型:w表示取钱,D表示存钱
-amount: double                      交易的金额
-balance: double                      交易后的余额
-description:String                  这笔交易的描述
---------------------------
+Transaction(type:char,amount:double,balance:double,description: String)

每个数据域前的"-"代表该数据域是被private修饰的,要提供set和get方法;
“+“代表是被public修饰的。

请问大神怎样解决?

作者: 海带    时间: 2015-4-15 00:29
问题自己已搞定!
作者: 时过境迁    时间: 2015-4-15 19:05
可以取钱么???
作者: zouxx    时间: 2015-4-15 20:29
:o感觉还没学到那里。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2