ATM machine project

atm machine

Below is a simple project Java code for an ATM machine simulation. This code allows users to perform basic ATM functions such as checking balance, withdrawing money, and depositing money.

This code defines a simple ATM class with methods for checking balance, withdrawing money, depositing money, and a menu for user interaction. The main method creates an instance of the ATM class and starts the ATM application, allowing users to interact with the menu until they choose to exit.

Here’s an example of how the output might look when you run the ATM program:

Python
import java.util.Scanner;

public class ATM {
    private double balance;
    private Scanner scanner;

    public ATM(double initialBalance) {
        balance = initialBalance;
        scanner = new Scanner(System.in);
    }

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

    public void withdraw(double amount) {
        if (amount > balance) {
            System.out.println("Insufficient funds");
        } else {
            balance -= amount;
            System.out.println("Withdrawal successful. Current balance is: $" + balance);
        }
    }

    public void deposit(double amount) {
        balance += amount;
        System.out.println("Deposit successful. Current balance is: $" + balance);
    }

    public void menu() {
        System.out.println("Welcome to the ATM!");
        System.out.println("1. Check Balance");
        System.out.println("2. Withdraw");
        System.out.println("3. Deposit");
        System.out.println("4. Exit");

        int choice = scanner.nextInt();

        switch (choice) {
            case 1:
                checkBalance();
                break;
            case 2:
                System.out.print("Enter amount to withdraw: $");
                double withdrawAmount = scanner.nextDouble();
                withdraw(withdrawAmount);
                break;
            case 3:
                System.out.print("Enter amount to deposit: $");
                double depositAmount = scanner.nextDouble();
                deposit(depositAmount);
                break;
            case 4:
                System.out.println("Thank you for using the ATM. Goodbye!");
                System.exit(0);
            default:
                System.out.println("Invalid choice");
        }
    }

    public static void main(String[] args) {
        ATM atm = new ATM(1000); // Starting balance is $1000
        while (true) {
            atm.menu();
        }
    }
}

Suppose you choose option 1 to check balance:

Python
Welcome to the ATM!
1. Check Balance
2. Withdraw
3. Deposit
4. Exit

Then, you choose option 2 to withdraw money and enter the amount to withdraw, for example, $200:

Python
Your balance is: $1000.0
Welcome to the ATM!
1. Check Balance
2. Withdraw
3. Deposit
4. Exit

Next, you choose option 3 to deposit money and enter the amount to deposit, for example, $500:

You can continue interacting with the menu until you choose option 4 to exit:

And the program terminates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Up
Python Framework & Libraries ,यह कर लिया तो आप की लाइफ सेट है Vladimir Putin, the President of Russia educational Qualification cybersecurity top 10 book American women top 10 fitness Sure, here are the 10 most important things about Dhruv Rathee