ATM Machine GUI Project
Project Structure:
You are required to implement an ATM machine simulation with a graphical user interface (GUI). The requirements are as follows:
Classes:
-
Main GUI Class:
-
Hand-code the GUI (do not use any GUI generators).
-
Must include:
-
A main method.
-
A constructor that builds the GUI.
-
Event handlers for each of the four buttons: Withdraw, Deposit, Transfer, Balance.
-
-
Withdraw button:
-
Check if the value in the text field is numeric.
-
Ensure the amount is in increments of $20.
-
Attempt to withdraw the amount from the selected account (Checking or Savings).
-
Handle exceptions for insufficient funds.
-
If any error occurs (non-numeric, wrong increment, insufficient funds), display an error message using
JOptionPane
. -
If successful, show a confirmation message.
-
-
Deposit button:
-
Only check if the amount is numeric.
-
Deposit the amount in the selected account.
-
-
Transfer button:
-
Check if the amount is numeric.
-
Ensure there are sufficient funds to transfer from the source account.
-
Transfer funds from one account to the other.
-
-
Balance button:
-
Show the current balance in the selected account using
JOptionPane
.
-
-
The main class must create two
Account
objects: one for Checking and one for Savings.
-
-
Account Class:
-
Should have:
-
A constructor.
-
Methods corresponding to each of the four GUI buttons.
-
Logic to deduct a $1.50 service charge after more than four withdrawals from either account combined.
-
The withdraw method should throw an
InsufficientFunds
exception if there is not enough balance (including the service charge when it applies).
-
-
-
InsufficientFunds Class:
-
A user-defined checked exception.
-
Coding Style Guidelines:
-
Make all variables private.
-
Name all constants.
-
Avoid code duplication.
-
Test the program with different scenarios.
the Answer
1. Main Class (ATM GUI) Explanation
-
Purpose: Handles the user interface and user actions.
-
How it works:
-
Users select the account (Checking/Savings) using radio buttons.
-
They enter an amount in the text field and choose an action by clicking a button.
-
Each button has an event handler that performs checks and calls methods in the Account class.
-
Results and errors are shown using dialog boxes (
JOptionPane
).
-
2. Account Class Explanation
-
Purpose: Models a bank account (Checking or Savings).
-
Functions:
-
Methods to withdraw, deposit, transfer, and get the balance.
-
Keeps track of total withdrawals (across both accounts).
-
After 4 withdrawals, applies a $1.50 service charge for every further withdrawal.
-
Throws a custom exception if trying to withdraw more than the available balance (including the service fee if applicable).
-
3. InsufficientFunds Exception Explanation
-
Purpose: Handles cases where the account does not have enough funds for the requested operation.
-
How it works:
-
When a withdrawal/transfer is attempted and there isn’t enough money, this exception is thrown.
-
The GUI catches the exception and shows an error message.
-
Start with an overview:
"This project simulates an ATM using a Java GUI, with separate classes for the GUI, account logic, and custom exception handling."
-
Show the main features and user flow:
-
Explain how the user interacts with the GUI.
-
Describe what happens when each button is clicked, focusing on validation and feedback.
-
-
Describe the Account logic:
-
Mention the service charge rule.
-
Explain how methods are separated for each operation.
-
-
Custom Exception:
-
Explain why and how you used a custom exception for insufficient funds.
-
-
Testing:
-
List a few scenarios you tested: e.g., trying to withdraw more than available, withdrawing in wrong increments, testing service charges after 4 withdrawals, etc.
-
-
Good practices:
-
Highlight the use of private variables, constants, and avoiding duplicate code.
-
1. InsufficientFunds.java