我正在做一个基于uml的银行系统,这是我最近得到的。我在完成一些方法时遇到了问题,而我自己尝试了一些方法来完成它。
如下所示。我的方法“addinterest()”不会向一个帐户的余额中添加任何类型的利息。可能是支票户头,也可能是储蓄户头。它只是没有添加它。
还有一个问题,在要求中说,在每一个新客户创建之后,就要创建两个帐户。我希望我做的是正确的,一些更正将不胜感激!我知道代码还没有100%完成,但我正在一点一点地完成。
帐户.java
package com.company;
public class Account {
public static Double interest = 0.042;
private static Long number = 0L;
private Double balance = 0.0;
public Account(Double interest, Long number, Double balance) {
number = Account.number;
balance = this.balance;
}
public void deposit(Integer amount) {
balance = balance + amount;
}
public double addInterest() {
return balance += balance * interest;
}
public double getBalance() {
return balance;
}
public static void main(String[] args) {
Account checkingaccount = new Account(interest, 1L, 0.0);
Account savingsaccount = new Account(interest, 1L, 0.0);
Customer customer = new Customer(1L, "John Doe", savingsaccount, checkingaccount);
checkingaccount.deposit(500);
savingsaccount.deposit(100);
checkingaccount.addInterest();
savingsaccount.addInterest();
System.out.println("Has a balance of " + checkingaccount.getBalance());
System.out.println("Has a balance of " + savingsaccount.getBalance());
System.out.println("Total balance is " + customer.totalBalance());
}
}
客户.java
class Customer {
private static Long lastNumber;
private String name;
private Account savingsAccount;
private Account checkingAccount;
public Customer(Long lastNumber, String name, Account savingsAccount, Account checkingAccount){
//add lastnumber
this.name = name;
this.savingsAccount = savingsAccount;
this.checkingAccount = checkingAccount;
}
public String getName(){
return this.name;
}
public Account getCheckingaccount(Account checkingaccount){
return checkingaccount;
}
//public Long getUniqueNumber(){
//
//}
public Account getSavingsaccount(Account savingsaccount){
// return savingsAccount info
return savingsaccount;
}
public double totalBalance(){
// return totalbalance
return savingsAccount.getBalance() + checkingAccount.getBalance();
}
}
1条答案
按热度按时间llycmphe1#
你好像没打电话来
addInterest()
在你的main()
方法或其他方法。你可以把它叫进去.deposit()
或者两者兼而有之.deposit()
来电main()
. 这取决于你想要的是什么Account
行为举止(例如,大多数银行在给定的时间线上加息,比如一个月加息一次)。