Presentation: Name: Alisha Ashraf Roll Number: COSC221101077 Course: Object Oriented Programming

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

PRESENTATION

Name: Alisha Ashraf


Roll Number : COSC221101077
Course: Object oriented Programming
ATM code

import java.util.Scanner;
// Initialize variables for user account
private int accountNumber=4595;
private int pin=000;
private double balance=1000;
// Method to deposit cash
public void deposit(double amount) {
balance += amount;
System.out.println("Deposit successfully");
System.out.println(" Your current balance is : " + balance);
}
Method to withdraw

// Method to withdraw cash


public void withdraw(double amount) {
if (amount > balance) {
System.out.println(" You cannot withdraw money due to insufficient balance ");
} else {
balance -= amount;
System.out.println("Withdrawal successful!");
System.out.println("New balance: " + balance);
}
}
Method to transfer
funds :
// // Method to transfer funds
public void transfer(double amount) {
if (amount > balance) {
System.out.println("You cannot transfer funds due to innsufficient balance ");
} else {
balance -= amount;
System.out.println("Transfer successfully!");
System.out.println("New balance: " + balance);
}
}
Method to check
balance :
public void checkBalance() {
System.out.println("Account balance: " + balance);
}
public static void main(String[] args) {
// Create an instance of the ATM object
ATM userAccount = new ATM();
// Prompt user to login
Scanner scanner = new Scanner(System.in);
System.out.print("Enter user account number: ");
int myaccountNumber = scanner.nextInt();
System.out.print("Enter account PIN: ");
int mypin = scanner.nextInt();
Login user & enter choice :

// Login user
if (myaccountNumber == userAccount.accountNumber && mypin ==
userAccount.pin) {
// Prompt user to select transaction type
While(true){
System.out.println("Welcome to ABC Bank. Please select one option :");
System.out.println("1. Deposit money ");
System.out.println("2. Withdraw money ");
System.out.println("3. Transfer funds");
System.out.println("4. Check user's account balance");
int choice = scanner.nextInt();
Using Switch :
switch (choice) {
case 1:
System.out.print("Enter deposit amount: ");
double depositAmount = scanner.nextDouble();
userAccount.deposit(depositAmount);
break;
case 2:
System.out.print("Enter withdrawal amount: ");
double withdrawalAmount = scanner.nextDouble();
userAccount.withdraw(withdrawalAmount);
break;
Using Switch :
case 3:
System.out.print("Enter transfer amount: ");
double transferAmount = scanner.nextDouble();
System.out.print("Enter recipient's account number: ");
int recipientAccountNumber = scanner.nextInt();
System.out.print("Enter Your PIN: ");
int recipientPin = scanner.nextInt();
userAccount.transfer(transferAmount);
break;
Using Switch :
case 4:
userAccount.checkBalance();
break;
default:
System.out.println("Invalid choice. Please try again.");
break;}}}}}

You might also like