0% found this document useful (0 votes)
22 views2 pages

IPA41

The document outlines the creation of a BankAccount class with attributes for account number, account holder name, and balance, along with their respective getters, setters, and a parameterized constructor. It also describes a Solution class containing static methods for withdrawing and depositing funds, which check for account existence and sufficient balance before updating the account. The main method demonstrates the functionality of these methods using sample input and expected output scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

IPA41

The document outlines the creation of a BankAccount class with attributes for account number, account holder name, and balance, along with their respective getters, setters, and a parameterized constructor. It also describes a Solution class containing static methods for withdrawing and depositing funds, which check for account existence and sufficient balance before updating the account. The main method demonstrates the functionality of these methods using sample input and expected output scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Create a class BankAccount with the following attributes:

accountNumber - int
accountHolderName - String
balance - double

Write getters, setters and parameterized constructor in the above mentioned


attribute sequence as required.

Create a class Solution with the main method.

Implement two static methods - withdraw and deposit in Solution class.

withdraw method:
------------------------------------------
This method will take two input parameters - array of BankAccount objects and the
account number (int) from which withdrawal
should be done.
The method will check if the account number is present in the array of BankAccount
objects.
If present, the method will then check if the balance is sufficient to withdraw the
requested amount (double). If yes, it will
deduct the amount from the account balance and return the updated balance.
If the account number is not present or the balance is not sufficient, the method
should return -1.

deposit method:
--------------------------------------------
This method will take two input parameters - array of BankAccount objects and the
account number (int) in which deposit should
be done.
The method will check if the account number is present in the array of BankAccount
objects.
If present, it will add the deposit amount (double) to the account balance and
return the updated balance.
If the account number is not present, the method should return -1.

These above mentioned static methods should be called from the main method.

For withdraw method - The main method should print the updated balance if the
returned value is greater than or equal to 0, or
it should print "Sorry - Insufficient balance" if the returned value is -1, or it
should print "Sorry - Account not found" if
the returned value is -2.

For deposit method - The main method should print the updated balance if the
returned value is greater than or equal to 0, or
it should print "Sorry - Account not found" if the returned value is -1.

Before calling these static methods in main, a parameterized constructor in the


above mentioned attribute sequence as required.

Input
------------------------
1001
Alice
5000.0
1002
Bob
10000.0
1003
Charlie
15000.0
1002
5000.0
1001
10000.0

Output
---------------------------
5000.0
15000.0

You might also like