import java.util.Random;
import java.util.Scanner;
public class test2 {
//Initialize everything that is needed
Random rand = new Random();
private int privatePin = rand.nextInt(9999)+1000;
private double currentMoney = 0;
//Method to display the ui
void showUI() {
System.out.println("===============JAVA BANKING SYSTEM===============");
System.out.println("Good day, User");
System.out.println("Your Current Balance: "+this.getCurrentMoney());
System.out.println("Your PIN is: "+this.getPin());
System.out.println("What would you like to do?");
System.out.println("( 1 ) Deposit Cash");
System.out.println("( 2 ) wí†hdráw Cash");
System.out.println("( 3 ) Exit program");
}
//Method to process the user's choice
void Process(int choice) {
if (choice == 3) {
System.out.println("===============END OF PROGRAM===============");
System.exit(0);
}
System.out.println("Input how much: ");
double money = sc.nextDouble();
System.out.println("Input your PIN: ");
int pin = sc.nextInt();
if(pin == this.getPin()) {
switch(choice) {
case 1:
depositCash(money);
break;
case 2:
withrdawCash(money);
break;
}
}
else
System.out.println("Invalid PIN");
}
//Deposit cash
void depositCash(double money) {
currentMoney += money;
}
//Withraw cash
void withrdawCash(double money) {
if(currentMoney > money) {
currentMoney -= money;
System.out.println("Sucessfully Wihtrawn");
}
else
System.out.println("Balance not sufficient");
}
int getPin() {
return privatePin;
}
double getCurrentMoney() {
return currentMoney;
}
static Scanner sc = new Scanner (System.in);
public static void main(String []args){
int choice;
//Call the class object
test2 obj = new test2();
do {
obj.showUI();
System.out.println("Input your choice: ");
choice = sc.nextInt();
obj.Process(choice);
}while(true);
}
}