PF Assin 03
PF Assin 03
DATE:09/12/2024
CODE:
import java.util.Scanner;
int pinAttempts = 0;
boolean accessGranted = false;
if (!accessGranted) {
System.out.println("Too many invalid attempts. Access blocked.");
return;
}
while (true) {
System.out.println("\nATM Menu:");
System.out.println("1. Check Balance");
System.out.println("2. Withdraw Money");
System.out.println("3. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
try {
if (!isHardwareWorking) {
throw new Exception("Hardware Error: Card reader or cash dispenser malfunction.");
}
if (!isNetworkAvailable) {
throw new Exception("Network Error: Unable to connect to the bank's central
system.");
}
switch (choice) {
case 1:
case 2:
case 3:
default:
System.out.println("Invalid option. Please choose again.");
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}
}
OUTPUT:
Enter your PIN: 2345
Invalid PIN. Try again.
Enter your PIN: 1234
ATM Menu:
1. Check Balance
2. Withdraw Money
3. Exit
Choose an option: 1
Your current balance is: $10000.0
ATM Menu:
1. Check Balance
2. Withdraw Money
3. Exit
Choose an option: 2
Enter the amount to withdraw: 2000
Transaction successful. Please collect your cash.
ATM Menu:
1. Check Balance
3. Exit
Choose an option: 3
Thank you for using the ATM. Goodbye!
PS C:\Users\hp\Desktop\javaCodes\2Darrays.java> ^C
PS C:\Users\hp\Desktop\javaCodes\2Darrays.java>
PS C:\Users\hp\Desktop\javaCodes\2Darrays.java> c:; cd 'c:\Users\hp\Desktop\javaCodes\
2Darrays.java'; & 'C:\Program Files\Java\jdk-22\bin\java.exe' '-
agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:59648' '-XX:
+ShowCodeDetailsInExceptionMessages' '-cp' 'C:\Users\hp\AppData\Roaming\Code\User\
workspaceStorage\8786173d550aeed683bee960273cc8ee\redhat.java\jdt_ws\
2Darrays.java_6ae26f3e\bin' 'pf_assign_3_sp24_bcs_065'
Enter your PIN: 1234
ATM Menu:
1. Check Balance
2. Withdraw Money
3. Exit
Choose an option: 1
Your current balance is: $10000.0
ATM Menu:
1. Check Balance
2. Withdraw Money
3. Exit
Choose an option: 2
Enter the amount to withdraw: 11000
Error: Insufficient Balance: You cannot withdraw more than your available balance.
ATM Menu:
1. Check Balance
2. Withdraw Money
3. Exit
Choose an option: 3
Thank you for using the ATM. Goodbye!
PS C:\Users\hp\Desktop\javaCodes\2Darrays.java>