NewAccount.java
package account;
import java.util.ArrayList;
public class NewAccount extends Account
{
//data_field
private String name;
private ArrayList<Transation> transation;
//constructor
NewAccount(int id, double balance, String name)
{
super(id, balance);
this.name = name;
this.transation = new ArrayList<Transation>();
}
//method
String getName()
{
return name;
}
ArrayList<Transation> getTransation()
{
return transation;
}
//override_method
@Override
void withDraw(double money)
{
/*no need*/
// if(money > getBalance())
// System.out.println("Your balance is not enough!");
// else
// setBalance(getBalance() - money);
super.withDraw(money);
Transation tempT = new Transation('W', money, super.getBalance(), "withdarw " + money);
transation.add(tempT);
}
@Override
void deposite(double money)
{
super.deposite(money);
Transation tempT = new Transation('D', money, super.getBalance(), "deposite " + money);
transation.add(tempT);
}
//main
public static void main(String[] args)
{
NewAccount na = new NewAccount(1122, 1000, "George");
na.setARate(0.015);
na.deposite(30);
na.deposite(40);
na.deposite(50);
na.withDraw(5);
na.withDraw(4);
na.withDraw(2);
System.out.println("Name: " + na.getName() + '\n' + "Annual Interest Rate: " +
na.getARate() + '\n' + "Balance: " + na.getBalance());
System.out.println("交易记录:");
for(int i = 0; i < na.getTransation().size(); i++)
{
System.out.println(na.getTransation().get(i).toString());
}
}
}
Transation.java
package account;
import java.util.Date;
public class Transation
{
//data field
private Date date;
private char type;
private double amount;
private double balance;
private String description;
//constructor
Transation()
{
date = new Date();
description = new String();
}
Transation(char type, double amount, double balance, String description)
{
this.date = new Date();
this.type = type;
this.amount = amount;
this.balance = balance;
this.description = description;
}
//override
public String toString()
{
return "OPERATE TYPE " + type + " : " + description + " / balance " + balance + " / operate time " + date.toString();
}
}
本文档将介绍如何在已有的Account类基础上扩展,新增一个ArrayList类型的transactions数据域,用于存储账户的交易记录。通过引入Transaction类,详细说明如何实现交易对象的创建和管理,以增强账户管理的功能。
936

被折叠的 条评论
为什么被折叠?



