Make a complete Java program called AtmSimulator that simulates a simple ATM acc
ID: 3665682 • Letter: M
Question
Make a complete Java program called AtmSimulator that simulates a simple ATM according to the following guidelines.
The program should start with an initial account balance, which you can set to any legitimate double value. Prompt the user with this prompt
Enter a transaction type (Balance, Deposit, or Withdrawal): to enter a transaction type which can be Balance, Deposit or Withdrawal.
If a balance is requested, the program should output “Your balance is X” where X is the initial balance, and then terminate.
If the user enters an invalid transaction type, the program should output “Invalid transaction type” and then terminate.
For a deposit or withdrawal, prompt the user to enter the transaction amount, which in your program should be stored in a double. Add or subtract this transaction amount from the initial balance and then output “Your current balance is X” where X is the balance after the transaction, and then terminate.
If the user attempts to withdraw more than the existing balance, the program should output “Insufficient funds” and terminate.
Explanation / Answer
import java.util.Scanner; public class ATM_Transaction { public static void main(String args[] ) { int balance = 5000, withdraw, deposit; Scanner s = new Scanner(System.in); while(true) { System.out.println("Automated Teller Machine"); System.out.println("Choose 1 for Withdraw"); System.out.println("Choose 2 for Deposit"); System.out.println("Choose 3 for Check Balance"); System.out.println("Choose 4 for EXIT"); System.out.print("Choose the operation you want to perform:"); int n = s.nextInt(); switch(n) { case 1: System.out.print("Enter money to be withdrawn:"); withdraw = s.nextInt(); if(balance >= withdraw) { balance = balance - withdraw; System.out.println("Please collect your money"); } else { System.out.println("Insufficient Balance"); } System.out.println(""); break; case 2: System.out.print("Enter money to be deposited:"); deposit = s.nextInt(); balance = balance + deposit; System.out.println("Your Money has been successfully depsited"); System.out.println(""); break; case 3: System.out.println("Balance : "+balance); System.out.println(""); break; case 4: System.exit(0); } } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.