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

ATM Simulation Program in Java

The document contains a Java program that simulates an ATM with functionalities such as checking balance, depositing, withdrawing money, changing PIN, and displaying transaction history. It includes a main class that prompts the user for a PIN and presents a menu for various operations. The program maintains a transaction history and validates user inputs for each operation.

Uploaded by

ks9501189
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)
8 views5 pages

ATM Simulation Program in Java

The document contains a Java program that simulates an ATM with functionalities such as checking balance, depositing, withdrawing money, changing PIN, and displaying transaction history. It includes a main class that prompts the user for a PIN and presents a menu for various operations. The program maintains a transaction history and validates user inputs for each operation.

Uploaded by

ks9501189
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

// ATM Simulation Program

import [Link].*;

// ATM Class to handle operations

class ATM {

private Scanner s = new Scanner([Link]);

private int balance = 0;

private ArrayList<String> transactionHistory = new ArrayList<>();

// Check the balance

public void checkBalance() {

[Link]("Current Balance: $" + balance);

[Link]("Checked balance: $" + balance);

// Deposit money

public void deposit() {

[Link]("Enter amount to deposit: $");

int dep = [Link]();

if (dep <= 0) {

[Link]("Invalid amount. Deposit failed.");

return;

balance += dep;

[Link]("Deposit successful. New balance: $" + balance);

[Link]("Deposited: $" + dep);

}
// Withdraw money

public void withdraw() {

[Link]("Enter amount to withdraw: $");

int with = [Link]();

if (with > balance) {

[Link]("Insufficient Balance. Withdrawal failed.");

} else if (with <= 0) {

[Link]("Invalid amount. Withdrawal failed.");

} else {

balance -= with;

[Link]("Withdrawal successful. Remaining balance: $" +

[Link]("Withdrew: $" + with);

// Change the PIN

public void changePin(int currentPin, Scanner sc) {

[Link]("Enter your current PIN: ");

int enteredPin = [Link]();

if (enteredPin != currentPin) {

[Link]("Incorrect PIN. PIN change failed.");

return;

[Link]("Enter your new PIN: ");

int newPin = [Link]();

[Link]("Confirm your new PIN: ");


int confirmPin = [Link]();

if (newPin == confirmPin) {

[Link]("PIN changed successfully.");

[Link]("PIN changed.");

} else {

[Link]("PIN mismatch. PIN change failed.");

// Display transaction history

public void showTransactionHistory() {

[Link]("\n--- Transaction History ---");

if ([Link]()) {

[Link]("No transactions available.");

} else {

for (String transaction : transactionHistory) {

[Link](transaction);

// Main class

public class task1 {

public static void main(String[] args) {

int pin = 1234;

int option = 0;
Scanner sc = new Scanner([Link]);

ATM atm = new ATM();

[Link]("Enter PIN: ");

int inputPin = [Link]();

if (inputPin != pin) {

[Link]("Incorrect PIN. Access denied.");

} else {

while (option != 6) {

[Link]("\n--- ATM Menu ---");

[Link]("1. Check Balance");

[Link]("2. Deposit Money");

[Link]("3. Withdraw Money");

[Link]("4. Change PIN");

[Link]("5. Transaction History");

[Link]("6. Quit");

[Link]("Enter Option: ");

option = [Link]();

switch (option) {

case 1:

[Link]();

break;

case 2:

[Link]();

break;
case 3:

[Link]();

break;

case 4:

[Link](pin, sc);

break;

case 5:

[Link]();

break;

case 6:

[Link]("Thank you for using the ATM. Goodby

break;

default:

[Link]("Invalid option. Please try again.")

break;

[Link]();

You might also like