KEMBAR78
Mini Project Simple ATM Machine | PDF
0% found this document useful (0 votes)
83 views2 pages

Mini Project Simple ATM Machine

The document describes a simple console-based ATM program implemented in Java. It allows users to check their balance, deposit, and withdraw money using methods, loops, and a menu-driven interface. The program includes error handling for insufficient funds and invalid menu choices.

Uploaded by

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

Mini Project Simple ATM Machine

The document describes a simple console-based ATM program implemented in Java. It allows users to check their balance, deposit, and withdraw money using methods, loops, and a menu-driven interface. The program includes error handling for insufficient funds and invalid menu choices.

Uploaded by

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

Mini Project: Simple ATM Machine

Purpose:
A basic console-based ATM program that:
✔ Lets a user check balance
✔ Deposit money
✔ Withdraw money
✔ Uses if-else, switch, loops, methods, and variables

import java.util.Scanner;

public class SimpleATM {


private double balance = 1000.0; // Initial balance

// Method to check balance


void checkBalance() {
System.out.println("Your current balance is: $" + balance);
}

// Method to deposit money


void deposit(double amount) {
balance += amount;
System.out.println("Deposited: $" + amount);
}

// Method to withdraw money


void withdraw(double amount) {
if (amount > balance) {
System.out.println("Insufficient funds!");
} else {
balance -= amount;
System.out.println("Withdrawn: $" + amount);
}
}

public static void main(String[] args) {


Scanner input = new Scanner(System.in);
SimpleATM atm = new SimpleATM();

int choice;
do {
System.out.println("\n=== ATM Menu ===");
System.out.println("1. Check Balance");
System.out.println("2. Deposit");
System.out.println("3. Withdraw");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
choice = input.nextInt();

switch (choice) {
case 1:
atm.checkBalance();
break;
case 2:
System.out.print("Enter amount to deposit: ");
double depositAmount = input.nextDouble();
atm.deposit(depositAmount);
break;
case 3:
System.out.print("Enter amount to withdraw: ");
double withdrawAmount = input.nextDouble();
atm.withdraw(withdrawAmount);
break;
case 4:
System.out.println("Thank you for using the ATM!");
break;
default:
System.out.println("Invalid choice. Please try again.");
}
} while (choice != 4);

input.close();
}
}

You might also like