2017-04-09 172 views
-4

大家好我有一個關於Bank.java聚合和繼承關係

的問題,我有這樣的問題:
銀行系統需要存儲有關銀行AccountsCustomers信息。銀行支持兩種不同類型的賬戶(檢查和儲蓄)。所有銀行賬戶都有賬戶Number,餘額和date opened。針對所有帳戶定義了兩項操作,分別爲makeDeposit()makeWithdrawal()。支票帳戶有額外的檢查風格和最小余額屬性。儲蓄賬戶有額外的利率屬性和calculateInterest()的操作。

所有客戶都有nameaddressphone number。另外,客戶可以擁有他需要的賬戶數量。
以上規格已經擴展了新的要求如下:有兩種特殊類型的客戶(PersonalCommercial)。商業客戶具有額外的信用評級,聯繫人和聯繫人電話屬性。個人客戶的屬性爲home phonework phone。此外,擴大模型以顯示該銀行有多個分行,並且每個賬戶由一個分行提供服務。當然,每個分支都有很多賬戶。
創建一個簡單的測試程序(不需要使用GUI或異常處理,只需要簡單)。這個測試程序的名稱是Bank.java,它應該使用上面的類。 Bank.java應聲明ArrayList持有所有銀行帳戶。測試程序應該利用系統功能;以下是演示系統功能的示例操作:

a。爲芝加哥分行的商業客戶創建一個支票帳戶,並將其添加到數組列表
b。創建一個單獨的方法來顯示客戶信息和賬戶餘額。代表您在上一步中創建的客戶調用方法。
c。將$ 100存入您在'a'中創建的帳戶,然後顯示新信息。 d。爲初始餘額爲100美元,利率爲10%的某個分行中的某個客戶創建一個儲蓄賬戶,並將其添加到數組列表中。 e。顯示儲蓄賬戶信息
f。向儲蓄賬戶存入100美元存款,計算利息,然後顯示信息
g。實施您選擇的其他操作!

這是我的代碼我已經寫了除了Bank.java類以外的所有東西,我不知道從哪裏開始或如何去做,請任何人幫助我或讓我知道該怎麼做。

在這裏你可以找到我的代碼:

public abstract class Account{ 
    protected String accountNumber; 
    protected double balance; 
    protected String dateOpened; 
    protected Customer state; 
    protected Customer customer; 

    public Account(){ 
     this.accountNumber = ""; 
     if (balance < 0) 
      balance = 0.0; 
     this.balance = 0.0; 
     this.dateOpened = ""; 
     state = null; 
     customer = null; 
    } 
    public Account (String accountNumber,double balance,String dateOpened, Customer state,Customer customer){ 
     this.accountNumber = accountNumber; 
     this.balance = balance; 
     this.dateOpened = dateOpened; 
     this.state = state; 
     this.customer = customer; 
    } 
    public void setCustomer(Customer customer){ 
     this.customer = customer; 
    } 
    public Customer getCustomer(){ 
     return customer; 
    } 
    public void setState(Customer state){ 
     this.state = state; 
    } 
    public Customer getState(){ 
     return state; 
    } 
    public void setAccountNumber(String accountNumber){ 
     this.accountNumber = accountNumber; 
    } 
    public String getAccountNumber(){ 
     return accountNumber; 
    } 
    public void setBalance(double balance){ 
     this.balance = balance; 
    } 
    public double getBalance(){ 
     return balance; 
    } 
    public void setDateOpened(String dateOpened){ 
     this.dateOpened = dateOpened; 
    } 
    public String getDateOpened(){ 
     return dateOpened; 
    } 
    public void makeDeposit(double depositAmount) { 
     balance = balance + depositAmount; 
     } 
    public void makeWithdrow(double withdrowAmount){ 
     balance = balance - withdrowAmount; 
    } 

    public String toString(){ 
     String output = ""; 
     output += "\nCustomer State: " + this.state; 
     output += "\nCustomer Customer: " + this.customer; 
     output += "\nAccount Number: " + this.accountNumber; 
     output += "\nAccount Balance: " + this.balance; 
     output += "\nAccount Date Opened: " + this.dateOpened; 
     return output; 
    } 

} 

public class Customer { 
    protected String name; 
    protected String address; 
    protected String phone; 


    public Customer(){ 
     this.name = ""; 
     this.address = ""; 
     this.phone = ""; 
    } 
    public Customer(String name,String address,String phone){ 
     this.name = name; 
     this.address = address; 
     this.phone = phone; 
    } 
    public void setName(String name){ 
     this.name = name; 
    } 
    public String getName(){ 
     return name; 
    } 
    public void setAddress(String address){ 
     this.address = address; 
    } 
    public String getAddress(){ 
     return address; 
    } 
    public void setPhone(String phone){ 
     this.phone = phone; 
    } 
    public String getPhone(){ 
     return phone; 
    } 
    public String toString(){ 
     String output = ""; 
     output += "\nCustomer Name: " + this.name; 
     output += "\nCustomer Address: " + this.address; 
     output += "\nCustomer Phone: " + this.phone; 
     return output; 
    } 

} 

public class CheckingAcount extends Account { 
    private String checkStyle; 
    private String minumumBalance; 

    public CheckingAcount(){ 
     this.checkStyle = ""; 
     this.minumumBalance = ""; 
    } 
    public CheckingAcount(String checkStyle,String minumumBalance){ 
     this.checkStyle = checkStyle; 
     this.minumumBalance = minumumBalance; 
    } 
    public CheckingAcount(String checkStyle,String minumumBalance,String accountNumber,double balance,String dateOpened,Customer state,Customer customer){ 
     super(accountNumber,balance,dateOpened,state,customer); 
     this.checkStyle = checkStyle; 
     this.minumumBalance = minumumBalance; 
    } 
    public CheckingAcount(String accountNumber,double balance,String dateOpened,Customer state,Customer customer){ 
     super(accountNumber,balance,dateOpened,state,customer); 
    } 
    public void setCheckStyle(String checkStyle){ 
     this.checkStyle = checkStyle; 
    } 
    public String getCheckStyle(){ 
     return checkStyle; 
    } 
    public void setMinumumBalance (String minumumBalance){ 
     this.minumumBalance = minumumBalance ; 
    } 
    public String getMinumumBalance(){ 
     return minumumBalance ; 
    } 
    public String toString(){ 
     String output = ""; 
     output += "\nAccount Number: " + this.accountNumber; 
     output += "\nAccount Balance: " + this.balance; 
     output += "\nAccount Date Opened: " + this.dateOpened; 
     output += "\nChecking Account Check Style: " + this.checkStyle; 
     output += "\nChecking Account Minumum Balance: " + this.minumumBalance; 
     return output; 
    } 
} 

public class SavingAccount extends Account { 

    private double intrestRate; 

    public SavingAccount(){ 
     this.intrestRate = 0.0; 
    } 
    public SavingAccount(double intrestRate){ 
     if (intrestRate < 0) 
      intrestRate = 0.0; 
     this.intrestRate = intrestRate; 
    } 
    public SavingAccount(double intrestRate, String accountNumber,double balance,String dateOpened,Customer state,Customer customer){ 
     super(accountNumber,balance,dateOpened,state,customer); 
     if (intrestRate < 0) 
      intrestRate = 0.0; 
     this.intrestRate = intrestRate; 
    } 
    public SavingAccount(String accountNumber,double balance,String dateOpened,Customer state,Customer customer){ 
     super(accountNumber,balance,dateOpened,state,customer); 
    } 
    public void setIntrestRate(double intrestRate){ 
     this.intrestRate = intrestRate; 
    } 
    public double getIntrestRate(){ 
     return intrestRate; 
    } 

    public double calculateInterest() { 
     return intrestRate; 
    } 
    public String toString(){ 
     String output = ""; 
     output += "\nAccount Number: " + this.accountNumber; 
     output += "\nAccount Balance: " + this.balance; 
     output += "\nAccount Date Opened: " + this.dateOpened; 
     output += "\nSavingAccount Intrest Rate: " + this.intrestRate; 
     return output; 
    } 
} 

public class Personal extends Customer { 
    private String homePhone; 
    private String workPhone; 

    public Personal(){ 
     this.homePhone = ""; 
     this.workPhone = ""; 

    } 
    public Personal(String homePhone,String workPhone){ 
     this.homePhone = homePhone; 
     this.workPhone = workPhone; 
    } 
    public Personal(String homePhone,String workPhone,String name,String address,String phone){ 
     super(name,address,phone); 
     this.homePhone = homePhone; 
     this.workPhone = workPhone; 
    } 
    public Personal(String name,String address,String phone){ 
     super(name,address,phone); 
    } 
    public void setHomePhone(String homephone){ 
     this.homePhone = homephone; 
    } 
    public String getHomePhone(){ 
     return homePhone; 
    } 
    public void setWorkPhone(String workPhone){ 
     this.workPhone = workPhone; 
    } 
    public String getWorkPhone(){ 
     return workPhone; 
    } 
    public String toString(){ 
     String output = ""; 
     output += "\nCustomer Name: " + this.name; 
     output += "\nCustomer Address: " + this.address; 
     output += "\nCustomer Phone: " + this.phone; 
     output += "\nPersonal Home Phone: " + this.homePhone; 
     output += "\nPersonal Work Phone: " + this.workPhone; 
     return output; 
    } 
} 

public class Commercial extends Customer { 
    private double cridetRating; 
    private String contactPerson; 
    private String contactPersonPhone; 

    public Commercial(){ 
     this.cridetRating = 0.0; 
     this.contactPerson = ""; 
     this.contactPersonPhone = ""; 
    } 
    public Commercial(double cridetRating,String contactPerson,String contactPersonPhone){ 
     this.cridetRating = cridetRating; 
     this.contactPerson = contactPerson; 
     this.contactPersonPhone = contactPersonPhone; 
    } 
    public Commercial (double cridetRating,String contactPerson,String contactPersonPhone,String name,String address, String phone){ 
     super(name,address,phone); 
     this.cridetRating = cridetRating; 
     this.contactPerson = contactPerson; 
     this.contactPersonPhone = contactPersonPhone; 
    } 
    public Commercial (String name, String address, String phone){ 
     super (name,address,phone); 
    } 

    public void setCridetRating(double cridetRating){ 
     this.cridetRating = cridetRating; 
    } 
    public double getCridetRating(){ 
     return cridetRating; 
    } 
    public void setContactPerson(String contactPerson){ 
     this.contactPerson = contactPerson; 
    } 
    public String getContactPerson(){ 
     return contactPerson; 
    } 
    public void setContactPersonPhone(String contactPersonPhone){ 
     this.contactPersonPhone = contactPersonPhone; 
    } 
    public String getContactPersonPhone(){ 
     return contactPersonPhone; 
    } 
    public String toString(){ 
     String output = ""; 
     output += "\nCustomer Name: " + this.name; 
     output += "\nCustomer Address: " + this.address; 
     output += "\nCustomer Phone: " + this.phone; 
     output += "\nCommercial Cridet Rating: " + this.cridetRating; 
     output += "\nCommercial Contact Person: " + this.contactPerson; 
     output += "\nCommercial Contact Person Phone: " + this.contactPersonPhone; 
     return output; 
    } 
} 
+2

由於各種原因,很多人不會遵循鏈接。通過不包括你的代碼,你正在減少找到你的問題的答案的機會。您也可能會收到反對票。 – MikeT

+0

爲什麼你不能嘗試編碼任何你想完成的事情,並提出問題,如果你卡住了 – prasanth

+0

我確實把我的代碼。 – Skarali

回答

0

看起來你是在與你的類對象正確的方向前進。當你認爲自己超級卡住時,你還有更多的事情要做。

提示:Commerical vs Non-Commerical嘗試Account類對象上的true/false屬性,應該消除對多個列表的需求,但它確實會增加複雜性。把它放在這裏創造你正在尋找的關係我相信。