Question: a Java program to demonstrate the use of inheritance and polymorphism. This program will also use theVectorclass. Class Definitions: You are to begin with the

a Java program to demonstrate the use of inheritance and polymorphism. This program will also use theVectorclass.

Class Definitions:

You are to begin with the following class:

Account.java

abstract class Account { protected String accountNo, institution, name; protected double balance; public Account (String accountNo, String name, String institution, double balance) { this.name = name; this.accountNo = accountNo; this.balance = balance; this.institution = institution; } public String getAccount() { return accountNo; } abstract boolean debitAccount(double amt); abstract boolean creditAccount(double amt); } 

Copy

You are also given this template code for Project4.

Project4.java

import java.util.Vector; public class Project4 { private static Account findAccount(Vector a, String acctNo) { // add code here! } private static void showAccounts(Vector all) { // add code here! } public static void main(String[] args) { Vector accounts = new Vector(); Account a; accounts.add(new CheckingAccount("10-3784665", "Joe Holder", "Chase", 2000)); accounts.add(new CreditCard("1234567898765432", "Bob Badger", "First Card", 4000)); accounts.add(new CheckingAccount("11-3478645", "Melissa Martin", "Dime", 1000)); showAccounts(accounts); if ( (a = findAccount(accounts, "10-3784665")) != null ) a.debitAccount(523.67); if ( (a = findAccount(accounts, "1234567898765432")) != null ) a.debitAccount(3500); if ( (a = findAccount(accounts, "10-3784665")) != null ) a.creditAccount(50); if ( (a = findAccount(accounts, "11-3478645")) != null ) a.creditAccount(30); if ( (a = findAccount(accounts, "10-839723")) != null ) a.debitAccount(200); if ( (a = findAccount(accounts, "1234567898765432")) != null ) a.debitAccount(600); showAccounts(accounts); } } 

Copy

You will create two additional files that are the classesCreditCard.javaandCheckingAccount.java. The two classes will be subclasses of theAccountclass defined above.

TheCheckingAcountclass needs no additional instance variables.

TheCreditCardclass will need two additional instance variables:

private double creditLimit; private double availableCredit; 

Copy

TheCheckingAccountandCreditCardclasses should define at least one constructor each. In addition, they should override the methodtoString()and provide thedebitAccount()andcreditAccount()abstracted methods.

Main Program:

Themain()method is responsible for simulating some account transactions.

You are required to create two additional methods (already shown above in themain()method):

private static Account findAccount(Vector a, String acctNo) { } private static void showAccounts(Vector all) { } 

Copy

The first method will assist you in finding an account in the vector that is to have the transaction applied to it. ThefindAccount()method should returnnullif the account is not found in theVector.

The second method is for displaying account summary details (see below).

Details of the transactions:

  • All accounts will be stored in a singleVectorafter they are created.
  • New credit cards have a zero balance and the credit limit is specified in the constructor.
  • New checking accounts have the balance specified in the constructor.
  • A debit is a subtraction in all cases.
  • A credit is an addition all cases.
  • A debit must be denied when there is insufficient funds or greater than available credit.
  • The credit cardavailableCreditmust be accurately maintained.
  • All data from showAccount() is to be sent to the screen.
  • Any errors encountered should be written to the screen.

If your sub-classes are configured correctly, your output should look like this:

Account summary: Checking account #10-3784665 Bank: Chase Name on account: Joe Holder Balance: 2000.00 Credit Account #1234567898765432 Bank: First Card Issued to: Bob Badger Credit Limit: 4000 Balance: 0.00 Available credit: 4000.00 Checking account #11-3478645 Bank: Dime Name on account: Melissa Martin Balance: 1000.00 End Account Summary Count not find account "10-839723". Transaction denied: debit: 1234567898765432, $600.00. Account summary: Checking account #10-3784665 Bank: Chase Name on account: Joe Holder Balance: 1526.33 Credit Account #1234567898765432 Bank: First Card Issued to: Bob Badger Credit Limit: 4000 Balance: 3500.00 Available credit: 500.00 Checking account #11-3478645 Bank: Dime Name on account: Melissa Martin Balance: 1030.00 End Account Summary 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!