You are to program a virtual ATM machine using Java. The client wants a GUI for
ID: 3824238 • Letter: Y
Question
You are to program a virtual ATM machine using Java. The client wants a GUI for its virtual ATM. The program will allow a user to enter their personal pin number (only 4 numbers allowed from 0001 to 9999). The user then must choose which account they would like to make a transaction: Savings Account or Checking Account, or Loan Payment (such as a mortgage, a car loan, or a student loan). If the user chooses a savngs account, then the allowed transactions are either to add money to the saving account, or to withdraw money from the savings account. A balance must be given to the user at the end of the transaction. Assume that the user has a starting balance of $4000 in each of their checking and savings accounts. Error trapping: if a balance goes below $200, then an alert to the user will be issued. For the loan payments, the user is to choose whether the loan is for a mortgage, a student loan, an auto loan, or a personal loan. For Mortgage: assume $350,000 balance and payment of $3500 per month; For Student Loan: assume $75,000 balance and payment of $250 per month; For Auto Loan, assume $35,000 balance and payment of $500 per month; For Personal Loan, assume $5,000 and payment of $1000 per month. Test data: for savings account in order: deposit $2000, deposit $1500, withdraw $2500, final balance Test data for checking account in order: checks (in order) made in the amount of $120, $40, $700, $50, $1000, final balance. Test data for loan payment(s): see above and provide for at least two payments.
Explanation / Answer
import java.util.Scanner;
public class Main {
private double currentBal =1000;
Scanner input = new Scanner(System.in);
public void mainMenu(){
int selection;
System.out.print("Welcome to the Automated Teller Machine! ");
System.out.println("Select from the following menu options below: ");
System.out.println("========================");
System.out.println("| [1] Check Balance |");
System.out.println("| [2] Withdrawal |");
System.out.println("| [3] Deposit |");
System.out.println("| [4] Exit |");
System.out.println("========================");
System.out.print("Please select your option now: ");
selection =input.nextInt();
switch (selection){
case 1:
viewBalance();
break;
case 2:
withdrawFunds();
break;
case 3:
depositFunds();
break;
case 4:
System.out.println("Thank you for using ATM! Goodbye! ");
}
}
public void viewBalance() {
int selection1;
System.out.println("You have selected Balance. ");
System.out.println(" -- Your Current Balance is:$ " + currentBal);
System.out.println("Return to main menu? [1] for YES ");
selection1 =input.nextInt();
switch (selection1){
case 1:
mainMenu();
break;
}
}
public void withdrawFunds() {
int withdrawSelection;
System.out.println("Amount to withdraw: ");
System.out.println("[1] - $20");
System.out.println("[2] - $40");
System.out.println("[3] - $50");
System.out.println("[4] - $100");
System.out.println("[5] - MAIN MENU");
System.out.print("Please select your option now: ");
withdrawSelection =input.nextInt();
switch (withdrawSelection){
case 1:
accountWithdraw(20);
mainMenu();
break;
case 2:
accountWithdraw(40);
mainMenu();
break;
case 3:
accountWithdraw(50);
mainMenu();
break;
case 4:
accountWithdraw(100);
mainMenu();
break;
case 5:
mainMenu();
break;
}
}
public void accountWithdraw(int withdrawFunds){
currentBal = currentBal -withdrawFunds;
System.out.println("Please take your funds.");
}
public void depositFunds(){
int addSelection;
System.out.println("Amount to deposit: ");
System.out.println("[1] - $20");
System.out.println("[2] - $40");
System.out.println("[3] - $50");
System.out.println("[4] - $100");
System.out.println("[5] - MAIN MENU");
System.out.print("Please select your option now: ");
addSelection =input.nextInt();
switch (addSelection){
case 1:
accountAdd(20);
mainMenu();
break;
case 2:
accountAdd(40);
mainMenu();
break;
case 3:
accountAdd(50);
mainMenu();
break;
case 4:
accountAdd(100);
mainMenu();
break;
case 5:
mainMenu();
break;
}
}
public void accountAdd (int depositFunds){
currentBal = currentBal +depositFunds;
System.out.println("Thank you.");
}
public static void main(String[] args) {
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.