聚合和继承关系

时间:2017-04-09 01:59:07

标签: java

大家好,我对Bank.java有疑问

我有这样的问题:
银行系统需要存储有关银行AccountsCustomers的信息。银行支持两种不同类型的帐户(支票和储蓄)。所有银行帐户都有帐户Number,余额和date opened。为所有帐户makeDeposit()makeWithdrawal()定义了两个操作。检查帐户具有检查样式和最小余额的附加属性。保存帐户具有额外的利率属性和calculateInterest()的操作。

所有客户都有nameaddressphone number。此外,客户可以拥有他所需的帐户数量 上述规范已按照以下新要求进行了扩展:有两种特殊类型的客户(PersonalCommercial)。商业客户具有信用评级,联系人和联系人电话的附加属性。个人客户拥有home phonework phone的属性。此外,扩展模型以显示银行有多个分支,每个帐户由一个分支提供服务。当然,每个分支都有很多账户 创建一个简单的测试程序(不需要使用GUI或异常处理,只需使它非常简单)。该测试程序的名称为Bank.java,它应该使用上述类。 Bank.java应声明ArrayList以保留所有银行帐户。测试程序应该利用系统功能;以下是演示系统功能的示例操作:

一个。为芝加哥分公司的商业客户创建一个支票帐户,并将其添加到阵列列表中   湾创建一个单独的方法来显示客户信息和帐户余额。代表您在上一步中创建的客户调用该方法   C。将100美元存入您在“a”中创建的帐户,然后显示新信息   d。为某个分支机构中的单个客户创建一个储蓄帐户,初始余额为100美元,利率为10%,并将其添加到阵列列表中。   即显示储蓄账户信息
  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;
    }
}

1 个答案:

答案 0 :(得分:0)

看起来你的班级对象正朝着正确的方向前进。当你认为自己陷入困境时,我们仍然可以继续前进。

提示:Commerical与Non-Commerical在Account类对象上尝试true / false属性,应该不需要多个列表,但它确实会略微增加复杂性。把它放在这里创造了你所寻找的关系。我相信。