Java Question

Java Question. Write a test program with the following two methods:
a) creates objects of SavingsAccount and CheckingAccount.
b) creates a new method which takes polymorphic variables in the type of Account, e.g., withdrawAccount(Account account, double amount).
Account.java code given is below:
/********************************************************* Account **——————————————————-** -id: int ** -balance: double ** ————————— ** -dateCreated: String ** Account() ** Account(newid: int, newBalance: double) ** setId(newId: int) ** setBalance(newBalance: double) ** getId(): int ** getBalance(): double ** getDateCreated(): String ** withdraw(amount: double) ** deposit(amount: double) *********************************************************/
// Implement the Account classimport java.util.Date;
public class Account { // Data fields private int id; private double balance; private Date dateCreated;
// Constructors /** Creates a default account */ Account() { this(0, 0); }
/** Creates an account with the specified id and initial balance */ Account(int id, double balance) { this.id = id; this.balance = balance; dateCreated = new Date(); }
// Mutator methods /** Set id */ public void setId(int id) { this.id = id; }
/** Set balance */ public void setBalance(double balance) { this.balance = balance; }
// Accessor methods /** Return id */ public int getId() { return id; }
/** Return balance */ public double getBalance() { return balance; }
/** Return dateCreated */ public String getDateCreated() { return dateCreated.toString(); }
// Methods
/** Decrease balance by amount */ public void withdraw(double amount) { balance -= amount; toString(); }
/** Increase balance by amount */ public void deposit(double amount) { balance = amount; toString(); }
/** Return a String decription of Account class */ public String toString() { return “nAccount ID: ” id “nDate created: ” getDateCreated() “nBalance: $” String.format(“%.2f”, balance)); }}

Java Question

Place this order or similar order and get an amazing discount. USE Discount code “GWEXDDSRGCF10” for 10% discount

This question has been answered by our writers. you can buy the answer below or order your 0% plagiarized answer


Order your 0% plagiarized answer