0% found this document useful (0 votes)
7 views5 pages

Lab 6

Uploaded by

premsingh6121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Lab 6

Uploaded by

premsingh6121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

import java.util.

InputMismatchException;

import java.util.Scanner;

public class ATMSimulator

private static double balance = 10000.00; // Starting balance

static public double w,d;

public static void main(String[] args)

Scanner scanner = new Scanner(System.in);

boolean runATM = true;

System.out.println("=== Welcome to Simple ATM Machine ===");

System.out.println("Please Enter 6 Digit Account Number:");

int acnno = scanner.nextInt();

System.out.println("Please Enter 4 Digit Pin:");

String pin = scanner.next();

if(pin.equals("1234"))

System.out.println("Pin Validation Sucessful");

while (runATM)

showMenu();

try {

System.out.print("Choose an option: ");

int choice = scanner.nextInt();


switch (choice)

case 1:

checkBalance();

break;

case 2:

depositMoney(scanner);

break;

case 3:

withdrawMoney(scanner);

break;

case 4:

miniStatement();

break;

case 5:

System.out.println("Thank you for using the ATM. Goodbye!");

runATM = false;

break;

default:

throw new IllegalArgumentException("Invalid menu option selected.");

catch (InputMismatchException e)

System.out.println("Please enter a valid number.");

scanner.nextLine(); // Clear the invalid input

catch (IllegalArgumentException | ArithmeticException e)

System.out.println("Error: " + e.getMessage());


}

finally

System.out.println("\n--- Operation Completed ---\n");

else

System.out.println("InValid Pin Try Again");

scanner.close();

static void showMenu() {

System.out.println("1. Check Balance");

System.out.println("2. Deposit Money");

System.out.println("3. Withdraw Money");

System.out.println("4. Mini Statement");

System.out.println("5. Exit");

static void checkBalance() {

System.out.printf("Your current balance is: Rs. %.2f\n", balance);

static void miniStatement()

{
System.out.printf("\nDisplaying Last two Transaction (Mini Statement)");

System.out.printf("\nLast Amont Diposited Rs. "+ATMSimulator.d);

System.out.printf("\nLast Amont Withdrawn Rs. "+ATMSimulator.w);

static void depositMoney(Scanner scanner) {

System.out.print("Enter amount to deposit: ");

double amount = scanner.nextDouble();

if (amount <= 0) {

throw new IllegalArgumentException("Deposit amount must be greater than zero.");

ATMSimulator.d=amount;

balance += amount;

System.out.printf("Successfully deposited Rs. %.2f. New balance: Rs. %.2f\n", amount, balance);

static void withdrawMoney(Scanner scanner) {

System.out.print("Enter amount to withdraw: ");

double amount = scanner.nextDouble();

if (amount <= 0) {

throw new IllegalArgumentException("Withdrawal amount must be greater than zero.");

if (amount > balance) {

throw new ArithmeticException("Insufficient funds for this withdrawal.");

ATMSimulator.w=amount;

balance -= amount;
System.out.printf("Successfully withdrew Rs %.2f. Remaining balance: Rs %.2f\n", amount,
balance);

You might also like