Presentation: Name: Alisha Ashraf Roll Number: COSC221101077 Course: Object Oriented Programming
Presentation: Name: Alisha Ashraf Roll Number: COSC221101077 Course: Object Oriented Programming
Presentation: Name: Alisha Ashraf Roll Number: COSC221101077 Course: Object Oriented Programming
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
// 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;}}}}}