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

Coding

Uploaded by

sushidesuu25
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)
10 views

Coding

Uploaded by

sushidesuu25
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
You are on page 1/ 4

Satorre, Arriane BSIT 1-6

package atmprog;
import java.util.Scanner;
public class Atmprog {

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
int pin = 0;
int balance = 0;
int maxAttempts = 5;

System.out.println("Welcome to the ATM!");

System.out.print("Setup your 4-digit PIN: ");


pin = scanner.nextInt();
while (pin < 1000 || pin > 9999) {
System.out.println("Invalid PIN. Please enter a 4-digit PIN.");
System.out.print("Setup your 4-digit PIN: ");
pin = scanner.nextInt();
}

System.out.print("Enter initial deposit amount(Minimum of 100): ");


int initialDeposit = scanner.nextInt();
while (initialDeposit < 100) {
System.out.println("Initial deposit amount must not be less than 100. ");
System.out.print("Enter initial deposit amount: ");
initialDeposit = scanner.nextInt();
}
balance += initialDeposit;
System.out.println("Account created successfully." );

int attempts = 0;
while (attempts < maxAttempts) {
System.out.print("Enter your 4-digit PIN (Attempts left: " + (maxAttempts - attempts) + "):
");
int enteredPin = scanner.nextInt();

if (enteredPin == pin) {
System.out.println("PIN entered successfully. You can now access the main menu.");
break;
} else {
System.out.println("Incorrect PIN. Please try again.");
attempts++;
}
}

if (attempts == maxAttempts) {
System.out.println("Too many incorrect attempts. Account Locked. Exiting the program.");
System.exit(0);
}

// Main menu
int choice;
do {
System.out.println("\n1. Withdraw");
System.out.println("2. Deposit");
System.out.println("3. Check Balance");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();

switch (choice) {
case 1:
System.out.print("Enter withdrawal amount: ");
int withdrawalAmount = scanner.nextInt();
if (withdrawalAmount > 0 && withdrawalAmount <= balance) {
balance -= withdrawalAmount;
System.out.println("Withdrawal successful. Remaining balance: " + balance);
} else {
System.out.println("Insufficient Balance.");
}
break;
case 2:

System.out.print("Enter deposit amount: ");


int deposit = scanner.nextInt();

if (deposit > 0) {
balance += deposit;
System.out.println("Deposit successful. New balance: " + balance);
} else {
System.out.println("Invalid deposit amount.");
}

break;
case 3:
System.out.println("Your balance: " + balance);

break;
case 4:

System.out.println("Thank you for using the ATM. Goodbye!");


break;
default:
System.out.println("Invalid choice. Please try again.");
}
} while (choice != 4 && balance > 0);

scanner.close();
}

You might also like