可記錄多次存取信息
創(chuàng)新互聯(lián)建站2013年開創(chuàng)至今,先為雙流等服務(wù)建站,雙流等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為雙流企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;//聲明
public class TestNewaccount //測試類
{
public static void main(String[] args)
{
NewAccount account = new NewAccount("Mike",1122,1000);
account.setAnnualInterestRate(1.5/100);
account.deposit(30);
account.deposit(40);
account.deposit(50);
account.withDraw(5);
account.withDraw(4);
account.withDraw(2);
for(int i=0;i=money)
balance-=money;
}
public void deposit(double money)
{
balance+=money;
}
}
class Transaction//用戶交易信息類
{
private char type;
private Date date;
private double money;
private double balance;
private String description;
public Transaction(char type,double money,double balance,String description)
{
this.type=type;//交易類型(取款,存款)
date=new Date();//時(shí)間
this.money=money;//存取的多少
this.balance=balance;//交易完還剩多少錢
this.description=description;//交易備注
}
public String toString()
{
return "Type:"+type+" Money:"+money+" Balance:"+balance+" Date:"+date+" "+description;
}
}
class NewAccount extends Account//子類
{
private String name;//新增變量
ArrayList transaction=new ArrayList();//ArrayList方法
public NewAccount(String name,int id,double balance)
{
super(id,balance);
this.name=name;
}
public void withDraw(double x)//取錢
{
if(getBalance()>x)
{
setBalance(getBalance()-x);
transaction.add(new Transaction('W',x,getBalance(),""));//往ArrayList方法中加元素
}
}
public void deposit(double x)//存錢
{
setBalance(getBalance()+x);
transaction.add(new Transaction('D',x,getBalance(),""));
}
}