2017-04-09 173 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属性,应该消除对多个列表的需求,但它确实会增加复杂性。把它放在这里创造你正在寻找的关系我相信。