#C14871. Bank Account Operations
Bank Account Operations
Bank Account Operations
You are required to implement a BankAccount
class to simulate basic banking operations. The account should support deposit, withdraw operations (with an insufficient funds check), and retrieving the current balance. When a withdraw operation is attempted and the available balance is insufficient, the program must immediately print the message Insufficient funds
and skip the withdrawal.
After processing all operations, output the final balance of the account. The operations are provided via standard input, and the output (including any "Insufficient funds" messages) must be printed to standard output.
Functionality:
deposit(amount)
: Adds the specified amount to the balance.withdraw(amount)
: Deducts the specified amount from the balance if sufficient funds exist; otherwise, printsInsufficient funds
.getBalance()
: Returns the current balance.
inputFormat
The input is given via standard input and has the following structure:
- A string representing the account number.
- A string representing the account holder's name.
- A floating-point number representing the initial balance.
- An integer n that denotes the number of operations to process.
- n subsequent lines, each representing an operation. Each operation is provided in one of the following forms:
deposit X
: Deposit the amount X.withdraw X
: Withdraw the amount X (if sufficient funds exist).
outputFormat
The output should be printed to standard output and include:
- Any messages
Insufficient funds
that occur during processing (each printed on a new line as they occur). - The final balance of the account printed on the last line.
1234
John
1000
3
deposit 500
withdraw 300
withdraw 1500
Insufficient funds
1200
</p>