Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The second project involves writing a program that implements an ATM machine. Th

ID: 3664832 • Letter: T

Question

The second project involves writing a program that implements an ATM machine. The interface to the program should be a GUI that looks similar to the following:

The program should consist of three classes. The first class should define the GUI and should be hand-coded and not generated by a GUI generator. In addition to the main method and a constructor to build the GUI, event handlers will be needed to handle each of the four buttons shown above. When the Withdraw button is clicked, several checks must be made. The first check is to ensure the value in the text field is numeric. Next a check must be made to ensure the amount is in increments of $20. At that point an attempt to withdraw the funds is made from the account selected by the radio buttons. The attempt might result in an exception being thrown for insufficient funds, If any of those three errors occur a JOptionPane window should be displayed explaining the error. Otherwise a window should be displayed confirming that the withdrawal has succeeded. When the Deposit button is clicked the only necessary check is to ensure that the amount input in the textfield is numeric. Clicking the Transfer button signifies transferring funds to the selected account from the other account. The checks needed are to confirm that the amount supplied is numeric and that there are sufficient funds in the account from which the funds are being transferred. Clicking the Balance button will cause a JOptionPane window to be displayed showing the current balance in the selected account. The main class must contain twoAccount objects, one for the checking account and another for the savings account.

The second class is Account.It must have a constructor plus a method that corresponds to each of the four buttons in the GUI. It must also incorporate logic to deduct a service charge of $1.50 when more than four total withdrawals are made from either account. Note that this means, for example, if two withdrawals are made from the checking and two from the savings, any withdrawal from either account thereafter incurs the service charge. The method that performs the withdrawals must throw an InsufficientFunds exception whenever an attempt is made to withdraw more funds than are available in the account. Note that when service charges apply, there must also be sufficient funds to pay for that charge.

The third class is InsufficientFunds, which is a user defined checked exception.

Be sure to follow good programming style, which means making all instance and class variables private, naming all constants and avoiding the duplication of code. Furthermore you must select enough scenarios to completely test the program.

Explanation / Answer

package ATM;
import javax.swing.*;
public class ATM
{
private boolean userAuthenticated; //for authentication of user
private int currentAccountNumber; // present account number
private Screen screen; // for JOption
private CashDispenser cashDispenser; // virtual
private DepositSlot depositSlot; // deposit slot to virtual
private BankDatabase bankDatabase; //client account database
private LoginScreen loginScreen; // login through jframe
private MenuScreen menuScreen; // amount transaction
private WithdrawalScreen withdrawalScreen;
// this is for main menu options
private static final int INQUIRY = 1;
private static final int WITHDRAWAL = 2;
private static final int DEPOSIT = 3;
private static final int EXIT = 4;
public int mainMenuSelection = 0;
Transaction currentTransaction = null;
// initializes ATM constructor with the instance variables
public ATM()
{
userAuthenticated = false; // not a correct user
currentAccountNumber = 0; //start with no current account number
screen = new Screen(); // to create screen
cashDispenser = new CashDispenser(); // to create cash dispenser
depositSlot = new DepositSlot(); // to create deposit
bankDatabase = new BankDatabase(); // create account information
loginScreen = new LoginScreen();
menuScreen = new MenuScreen();
withdrawalScreen = new WithdrawalScreen();
} // constructor closed
public void run()
{
while ( true )
{
while ( !userAuthenticated ) // to check user authentication
{
login(); //log in process
currentAccountNumber = loginScreen.getCurrentAccountNumber();
userAuthenticated = loginScreen.getAuthentication();
}
currentAccountNumber = loginScreen.getCurrentAccountNumber();
performTransactions(); // cheched user authenticated
userAuthenticated = false; // if wrong reset ATM
currentAccountNumber = 0; // reset account ATM
screen.displayMessageLine( " Thank you " );
}
} // method closed
private void login()// constructor for login
{
loginScreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
loginScreen.setSize( 275, 130 ); // intialised frame size
loginScreen.setVisible( true ); // display
}
  
private void performTransactions()
{
boolean userExited = false;
while ( !userExited )
{
mainMenuSelection = displayMainMenu();
  
// to strat the process depends user option
switch ( mainMenuSelection )
{
// select any one option
case INQUIRY:
case WITHDRAWAL:
case DEPOSIT:

currentTransaction =
createTransaction( mainMenuSelection );
currentTransaction.execute(); // execute current transaction
break;
case EXIT: // exit from transaction
screen.displayMessageLine( " Exiting the system..." );
userExited = true; // end the trsnsaction
break;
} // closed switch
}
} // Transactions closed
//to display the main menu
private int displayMainMenu() //for the user choice
{
menuScreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
menuScreen.setSize( 275, 130 ); //initialize frame size
menuScreen.setVisible( true ); // display frame
return menuScreen.displayMainMenuValue; // return user's choice
} //closed the displayMainMenu method
private Transaction createTransaction( int choice )
{
Transaction temp = null;

switch (choice )
{
case INQUIRY: // case for BalanceInquiry
temp = new BalanceInquiry(
currentAccountNumber, screen, bankDatabase );
currentTransaction = null;
mainMenuSelection = 0;
break;
case WITHDRAWAL: // case for Withdrawal transaction
temp = new Withdrawal( currentAccountNumber, screen,
bankDatabase, cashDispenser );
currentTransaction = null;
mainMenuSelection = 0;
break;
case DEPOSIT: // case Deposit transaction
temp = new Deposit( currentAccountNumber, screen,
bankDatabase, depositSlot );
currentTransaction = null;
mainMenuSelection = 0;
break;
} // end switch
return temp; // return the new object
} // close Transaction
} // closed ATM class