不要自卑,去提升实力
互联网行业谁技术牛谁是爹
如果文章可以带给你能量,那是最好的事!请相信自己
加油o~

1、题目背景

银行账户类(Accoount)可以为账户存储交易。取款和存款都会产生交易信息。需要记录账户每次交易的信息,包括取钱还是存钱,交易的金额,交易时间和交易之后的余额。系统可以通过账户查询所有的交易次数(最多10次)。这里没有涉及用户的概念。

2、题目要求

为了实现此功能需要设计几个类?
这些类之间的关系是什么?请用UML图表示(注意单线关联和双向关联表示的不同)。
请写出你的设计的类的代码(先画UML图,图中标注主要数据域和方法,再展示代码)。
账户要包含用户名字、账户id,账户年利率,账户余额,账户所有的交易信息,账户创建的日期等信息(对实验六的Account类做部分修改)。
交易信息包含交易的时间,交易的类型(D表示取钱,W表示存钱),交易的数额、交易之后的余额。
编写一个测试程序,创建一个年利率为1.5%、收支额为1000、id为1122而名为George的Account。向账户存入30美元、40美元、50美元并从该账户中取出5美元、4美元、2美元。打印账户清单,显示账户持有者名字,利率,收支额和所有的交易。

以下代码仅供参考
以下代码仅供参考
以下代码仅供参考

最后的输出格式和编译器有关,不同编译器最终对齐方式可能有所不同,最终输出格式请自己修改。

/**
*作者:魏宝航
*2020年11月23日,下午16:04
*/
import java.util.Date;

public class Test{
public static void main(String[] args) {
Account George=new Account(1122,1000,"George");
Account.setAnnualInterestRate(150);
System.out.println("Name:"+George.getName());
System.out.println("Annual interest:"+George.getAnnual());
George.deposit(30);
George.deposit(40);
George.deposit(50);
George.withdraw(5);
George.withdraw(4);
George.withdraw(2);
System.out.println("Balance:"+George.getBalance());
System.out.println("Date\t\t\t\t"+"Type\t\t"+"Amount\t\t"+"Balance");
for(int i=0;i<George.data.count;i++){
System.out.println(George.data.string[i][0]);
}
}
}
class Account {
private int id;
private String name;
private double balance;
private static double annualInterestRate;//年利率
Data data=new Data();
private java.util.Date dateCreated;
{
dateCreated = new java.util.Date();
}
public Account() { }
public Account(int newId, double newBalance,String name) {
id = newId;
balance = newBalance;
this.name=name;
}
public int getId() { return this.id; }
public double getBalance() { return balance; }
public static double getAnnualInterestRate() { return annualInterestRate; }
public void setId(int newId) { id = newId; }
public void setBalance(double newBalance) {
if(newBalance>0)
balance = newBalance;
}
public static void setAnnualInterestRate(double newAnnualInterestRate) {
annualInterestRate = newAnnualInterestRate;
}
public String getName(){
return name;
}
public double getMonthlyInterest() { return balance * (annualInterestRate / 1200); }
public double getYearlyInterest() { return balance * (annualInterestRate / 100); }
public java.util.Date getDateCreated() { return dateCreated; }
public void withdraw(double amount) {
this.setBalance(balance-amount);
String s;
if(amount<10){
s=dateCreated+"\t"+"W"+"\t\t"+amount+"\t\t"+balance;
}
else{
s=dateCreated+"\t"+"W"+"\t\t"+amount+"\t\t"+balance;
}
data.string[data.count++][0]=s;
}
public void deposit(double amount) {
if(amount<0) return;
this.setBalance(balance+amount);
String s=dateCreated+"\t"+"D"+"\t\t"+amount+"\t\t"+balance;
data.string[data.count++][0]=s;
}
public double getAnnual(){
return annualInterestRate/100;
}
}
class Data{
Date date=new Date();
String type="";
double amount=0;
double balance=0;
int count=0;
String[][] string=new String[1000][1];
Data(){

}
Data(Date date,String type,double amount,double balance){
this.date=date;
this.type=type;
this.amount=amount;
this.balance=balance;
}
}