You are on page 1of 2

Hashimate University

Department of Computer Engineering

Data Structure
Lab 3 (Array and Inheritance)

Dr. Mohammad Al-Hammouri


March 23, 2024

Question

Please make the following changes to the ”BankSystem.java” class:


1. In the Account class, introduce the following new changes:
• An array named transactions of type Transaction.
• An int variable named transactionCount
• Within the Account constructor, allocate space for 50 elements in
the transaction array and set transactionCount to 0
• Implement the methods: getBalance(), and getCustomer().
• Implement the method:
protected void addTransaction(Transaction transaction)
(Please ensure you are within the bounds of the transaction array
size)
2. In the SavingsAccount which inherits (extend) from the Account class,
introduce the following changes:

• Implement the methods: public void deposit(double amount)


This method should increase the account’s balance by the specified
amount, which needs to be positive. Afterwards, it should record a
new transaction in the transaction array.
(Transaction(”DEPOSIT”, amount))
• Implement the methods: public void withdraw(double amount)

This method is designed to reduce the account’s balance by the spec-


ified amount. The amount must be positive and cannot exceed the
account’s current balance. After the withdrawal, the method should
log the transaction by adding it to the transactions array.
(Transaction(”WITHDRAW”, amount))

1
• toString() method that overrides the method in the Account base
class.

3. In the BankSystem class (Main class for testing the bank system), test
the following methods on the johnsAccount object: depostie(), addIn-
terst(), and withdraw(). Following these operations, output the state
(print) of johnsAccount to the console.

You might also like