Java Programming In the following class diagram, Account is already defined. Now
ID: 3840320 • Letter: J
Question
Java Programming
In the following class diagram, Account is already defined. Now define SavingAccount.java in which:
• the constructor uses four passed-in parameters to update values of all instance variables.
• toString() returns a String for all instance variable values of an SavingAccount object.
A sample return value of toString() for an SavingAccount object is as follows. The interest rate has three decimal places.
Customer ID: 4838156 Name: John Smith Account Number:
5820389 Balance: $5,280.05Interest Rate: 2.750%
Account accountNo: int customer: Customer balance: double Account(int, Customer, double) getAccountNo0: int set AccountNo(int) getCustomero: Customer setCustomer (Customer) getBalance double 0: setBalance(double) deposit double) withdraw(double): bookean toString String O: SavingAccount interest Rate: double SavingAccount (int, Customer, double, double) get InterestRateo: double setInterestRate(double) toStringo: StringExplanation / Answer
Customer.java
package accounts;
public class Customer {
private int custId;
private String custName;
public Customer(int no,String nm){
custId=no;
custName=nm;
}
public String toString(){
return "CustomerID: "+custId+" "
+ "Name: "+custName;
}
}
Account.java
package accounts;
public class Account {
private int accountNo;
private double balance;
private Customer customer;
public Account(int acc,Customer cust,double bal){
accountNo=acc;
customer=cust;
balance=bal;
}
public int getAccountNo() {
return accountNo;
}
public void setAccountNo(int accountNo) {
this.accountNo = accountNo;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public void withdraw(double amt){
balance=balance-amt;
}
public void deposite(double amt){
balance=balance+amt;
}
public String toString(){
return customer.toString()+" "
+ "Account Number: "+accountNo+" "
+ "Balance: "+balance;
}
}
SavingAccount.java
package accounts;
public class SavingAccount extends Account {
private double interestRate;
public SavingAccount(int acc,Customer cust,double balance,double intr){
super(acc,cust,balance);
interestRate=intr;
}
public double getInterestRate() {
return interestRate;
}
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
public String toString(){
return super.toString()+" "
+ "Interest Rate: "+interestRate+"%";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.