Java 聚合与继承关系
大家好,我有一个关于Bank.java的问题 我有以下问题:Java 聚合与继承关系,java,Java,大家好,我有一个关于Bank.java的问题 我有以下问题: 银行系统需要存储有关银行账户和客户的信息。银行支持两种不同类型的账户(支票账户和储蓄账户)。所有银行账户都有账户编号、余额和开户日期。为所有帐户定义了两个操作,makeDeposit()和makedrawing()。支票帐户具有支票样式和最低余额的附加属性。储蓄账户具有利率的附加属性和calculateInterest()的操作 所有客户都有姓名、地址、电话号码。此外,客户可以拥有所需的任意多个帐户。 上述规范已扩展为以下新要求:有两
银行系统需要存储有关银行
账户
和客户
的信息。银行支持两种不同类型的账户(支票账户和储蓄账户)。所有银行账户都有账户编号、余额和开户日期。为所有帐户定义了两个操作,makeDeposit()
和makedrawing()
。支票帐户具有支票样式和最低余额的附加属性。储蓄账户具有利率的附加属性和calculateInterest()
的操作
所有客户都有姓名
、地址
、电话号码。此外,客户可以拥有所需的任意多个帐户。上述规范已扩展为以下新要求:有两种特殊类型的客户(
个人
和商业
)。商业客户具有信用评级、联系人和联系人电话的附加属性。个人客户具有家庭电话
和工作电话
的属性。此外,扩展模型以显示银行有多个分行,每个账户由一个分行提供服务。当然,每个分行都有很多账户。创建一个简单的测试程序(无需使用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;
}
}
公共抽象类帐户{
受保护的字符串帐号;
保护双重平衡;
已打开的受保护字符串;
受保护的客户状态;
保护客户;
公共帐户(){
this.accountNumber=“”;
如果(余额<0)
余额=0.0;
此值为0.0;
此为“已打开日期”;
state=null;
customer=null;
}
公共帐户(字符串accountNumber、双倍余额、字符串dateOpened、客户状态、客户){
this.accountNumber=accountNumber;
这个平衡=平衡;
this.dateOpened=dateOpened;
this.state=状态;
this.customer=customer;
}
公共作废设置客户(客户){
this.customer=customer;
}
公共客户getCustomer(){
退货客户;
}
公共无效设置状态(客户状态){
this.state=状态;
}
公共客户getState(){
返回状态;
}
public void setAccountNumber(字符串accountNumber){
this.accountNumber=accountNumber;
}
公共字符串getAccountNumber(){
返回帐号;
}
公共余额(双倍余额){
这个平衡=平衡;
}
公共双getBalance(){
收益余额;
}
public void setDateOpened(字符串dateOpened){
this.dateOpened=dateOpened;
}
公共字符串getDateOpen(){
返回日期已打开;
}
公共存款(双倍存款额){
余额=余额+存款金额;
}
使用DROW生成公共无效(使用DROWAMOUNT加倍){
平衡=平衡-带drowamount;
}
公共字符串toString(){
字符串输出=”;
输出+=“\n客户状态:”+this.State;
输出+=“\n客户:”+此客户;
输出+=“\n计数编号:”+this.accountNumber;
输出+=“\n计数余额:”+this.Balance;
输出+=“\n计数打开日期:”+this.dateOpened;
返回输出;
}
}
公共类客户{
受保护的字符串名称;
受保护的字符串地址;
保护串电话;
公众客户(){
this.name=“”;
this.address=“”;
this.phone=“”;
}
公共客户(字符串名称、字符串地址、字符串电话){
this.name=名称;
this.address=地址;
this.phone=电话;
}
公共void集合名(字符串名){
this.name=名称;
}
公共字符串getName(){
返回名称;
}
公共无效设置地址(字符串地址){
this.address=地址;
}
公共字符串getAddress(){
回信地址;
}
公用无效设置电话(字符串电话){
this.phone=电话;
}
公共字符串getPhone(){
回电话;
}
公共字符串toString(){
字符串输出=”;
输出+=“\n客户名称:”+this.Name;
输出+=“\n客户地址:”+此地址;
输出+=”\n客户电话:“+this.Phone;
返回输出;
}
}
公共类checkingaccount扩展帐户{
私有字符串校验样式;