0% found this document useful (0 votes)
8 views6 pages

Exercises for Midterm Exam

The document outlines the design of two Java-like programs: one for a simple banking system managing multiple accounts and another for a bank's transaction record system using a two-dimensional array. The first program includes an Account class with methods for managing account balances, while the second program features a BankRecords class for handling customer transactions. Both programs require implementation of specified methods and tasks in their main functions.

Uploaded by

arslanarginemir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Exercises for Midterm Exam

The document outlines the design of two Java-like programs: one for a simple banking system managing multiple accounts and another for a bank's transaction record system using a two-dimensional array. The first program includes an Account class with methods for managing account balances, while the second program features a BankRecords class for handling customer transactions. Both programs require implementation of specified methods and tasks in their main functions.

Uploaded by

arslanarginemir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Question 1

Design a Java-like program to simulate a simple banking system that manages multiple
accounts using arrays and methods.

Class: Account

Fields (Attributes):

• accountNumber (String): stores the account number.

• balance (double): stores the current account balance.

Methods:

1. Constructor

o Account(String accountNumber, double balance)

o Initializes the account with the given number and balance.

2. deposit(double amount)

o Adds the given amount to the balance only if the amount is positive; otherwise
prints an error message.

3. withdraw(double amount)

o Subtracts the given amount from the balance only if sufficient funds exist;
otherwise prints "Insufficient balance!".

4. display()

o Displays the account number and current balance.

5. getBalance()

o Returns the balance of the account.

Methods (Array-based):

6. static double totalBalance(Account[] accounts)

o Calculates and returns the sum of all account balances.

7. static double averageBalance(Account[] accounts)

o Calculates and returns the average balance across all accounts.

8. static Account findMaxBalance(Account[] accounts)

o Finds and returns the account object with the highest balance.

9. static Account searchByNumber(Account[] accounts, String number)

o Searches the array for the given account number and returns the corresponding
Account object.

o If not found, returns null.


10. static void displayAll(Account[] accounts)

o Prints the account number and balance for every account in the array.

Tasks:

1. Implement the Account class with all required methods.

2. In the main() method:

o Create five Account objects with different initial balances.

o Store them in an array.

o Display all accounts using displayAll().

o Add 200 to each account using depositToAll() (you may reuse or write this helper
method).

o Display the total and average balance.

o Find and print the account with the maximum balance.

o Ask the user (or simulate) an account number to search, and display the result
(found or not found).

Question 2

Design a Java-like program that represents and manipulates a bank’s transaction record
system using a two-dimensional array inside a class.

Each row in the array represents a customer, and each column represents a transaction
amount (positive for deposit, negative for withdrawal).

The goal is to calculate and display useful information for all customers.

Class: BankRecords

Field:

• double[][] transactions – a 2D array that stores the transaction amounts for each
customer.

Methods:

1. Constructor

o BankRecords(double[][] data)

o Initializes the transactions array using the given 2D array.

2. void displayAll()

o Prints all transaction values in tabular form (each row = one customer).

3. double totalBalanceOfCustomer(int index)

o Returns the sum of all transaction values for the given customer (row).

4. double[] totalBalances()
o Returns a 1D array containing the total balance for each customer.

5. int findCustomerWithMaxBalance()

o Returns the index of the customer who has the highest total balance.

6. double averageTransaction()

o Returns the average transaction value across all customers.

7. void depositAll(double amount)

o Adds the given amount to every transaction entry (simulates a bonus or interest).

Tasks:

1. Implement the BankRecords class with all methods described above.

2. In the main() method:

o Create a 2D array double[][] data that represents at least 3 customers, each with
4 transactions.

o Create a BankRecords object using this array.

o Display all transactions.

o Print the total balance of each customer.

o Display the average transaction value of the bank.

o Apply a small bonus (e.g., +10) to all transactions using depositAll() and display
the updated table.

Solution 2:

You might also like