0% found this document useful (0 votes)
4 views

TASK 1 CODE

The document outlines a project to simulate a basic ATM machine, detailing essential functionalities such as balance inquiry, funds withdrawal, funds deposit, PIN change, and transaction history. It includes a problem statement, user interface requirements, and a Java code implementation for the ATM operations. The code demonstrates how users can interact with the ATM through a menu-driven approach while ensuring proper error handling and transaction logging.

Uploaded by

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

TASK 1 CODE

The document outlines a project to simulate a basic ATM machine, detailing essential functionalities such as balance inquiry, funds withdrawal, funds deposit, PIN change, and transaction history. It includes a problem statement, user interface requirements, and a Java code implementation for the ATM operations. The code demonstrates how users can interact with the ATM through a menu-driven approach while ensuring proper error handling and transaction logging.

Uploaded by

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

Project 1: SIMULATE THE BASIC FUCTION OF ATM

MACHINE

Project Title : SIMULATE THE BASIC FUCTION OF ATM MACHINE

Problem Statement : To develop a simulation of a basic ATM machine that


allows users to perform essential banking operations. The simulation should
provide a user-friendly interface to interact with the ATM and support core
functionalities such as checking account balance, withdrawing funds, and
depositing funds,Change pin,Transaction history.

COMMENTS:

ACCOUNT BALANCE INQUIRY:

 “After authentication, users can check their account balance. This feature
should display the current balance clearly and promptly, providing users
with up-to-date information on their finances.”

FUNDS WITHDRAWAL:

 “Users can request to withdraw a specified amount. The system should


verify that the requested amount does not exceed the available balance
and that it adheres to any daily withdrawal limits.”

 “Include error handling for cases where users attempt to withdraw more
than their balance or enter invalid amounts.”

FUNDS DEPOSIT:

 “Users can deposit funds into their account. The system should accept
deposit amounts and update the account balance accordingly.”

 “Ensure that deposit transactions are processed accurately and that users
are notified of successful deposits.”
PIN CHANGE PROCESS:

 “The PIN change process involves verifying the current PIN, entering a
new PIN, and confirming the new PIN. This ensures that the user is
authorized to make the change and that the new PIN is correctly set.”

FETCHING TRANSACTION HISTORY:

 “// When the user requests their transaction history, retrieve the most
recent transactions from the stored data. Limit the number of transactions
displayed to a manageable number, such as the last 10 transactions.”

 “// Provide options for users to view more transactions or navigate


through their transaction history if the list exceeds the default display
limit.

CODE:

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class ATM {
private static class Account {
private int pin;
private double balance;
private List<String> transactionHistory;
public Account(int pin, double initialBalance) {
this.pin = pin;
this.balance = initialBalance;
this.transactionHistory = new ArrayList<>();
this.transactionHistory.add("Initial deposit: $" + initialBalance);
}
public boolean validatePin(int pin) {
return this.pin == pin;
}
public void changePin(int newPin) {
this.pin = newPin;
}
public double getBalance() {
return balance;
}
public void deposit(double amount) {
this.balance += amount;
this.transactionHistory.add("Deposited: $" + amount);
}
public boolean withdraw(double amount) {
if (amount > balance) {
System.out.println("Insufficient funds.");
return false;
}
this.balance -= amount;
this.transactionHistory.add("Withdrew: $" + amount);
return true;
}
public void printTransactionHistory() {
System.out.println("Transaction History:");
for (String transaction : transactionHistory) {
System.out.println(transaction);
}
}
}
private static Account account;
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
account = new Account(1234, 1000.00); // Initial PIN is 1234 and initial balance is
$1000

while (true) {
System.out.println("\nATM Menu:");
System.out.println("1. Balance Inquiry");
System.out.println("2. Cash Withdrawal");
System.out.println("3. Cash Deposit");
System.out.println("4. Change PIN");
System.out.println("5. Transaction History");
System.out.println("6. Exit");
System.out.print("Please select an option: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
balanceInquiry();
break;
case 2:
cashWithdrawal();
break;
case 3:
cashDeposit();
break;
case 4:
changePin();
break;
case 5:
transactionHistory();
break;
case 6:
System.out.println("Thank you for using our ATM.");
System.exit(0);
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
private static void balanceInquiry() {
System.out.println("Your balance is: $" + account.getBalance());
}
private static void cashWithdrawal() {
System.out.print("Enter the amount to withdraw: $");
double amount = scanner.nextDouble();
if (account.withdraw(amount)) {
System.out.println("Withdrawal successful.");
}
}
private static void cashDeposit() {
System.out.print("Enter the amount to deposit: $");
double amount = scanner.nextDouble();
account.deposit(amount);
System.out.println("Deposit successful.");
}
private static void changePin() {
System.out.print("Enter your current PIN: ");
int currentPin = scanner.nextInt();
if (account.validatePin(currentPin)) {
System.out.print("Enter your new PIN: ");
int newPin = scanner.nextInt();
account.changePin(newPin);
System.out.println("PIN changed successfully.");
} else {
System.out.println("Invalid PIN.");
}
}
private static void transactionHistory() {
account.printTransactionHistory();
}
}

SAMPLE OUTPUT:

ATM Menu:

1. Balance Inquiry

2. Cash Withdrawal

3. Cash Deposit

4. Change PIN

5. Transaction History

6. Exit

Please select an option:

You might also like