package april20;
import java.util.*;
public class Bank {
public static HashMap<String, String> accountCredentials = new HashMap<String, String>();
public static HashMap<String, Integer> accountBalance = new HashMap<String, Integer>();
Bank() {
accountCredentials.put("1234567890", "1234");
accountBalance.put("1234567890", 13435);
accountCredentials.put("0987654321", "0987");
accountBalance.put("0987654321", 100);
accountCredentials.put("1029384756", "3423");
accountBalance.put("1029384756", 29);
accountCredentials.put("9087653421", "9348");
accountBalance.put("9087653421", 12345678);
}
public String login(Scanner sc) {
boolean loggedIn = false;
do {
System.out.println("Enter your account number: ");
String acno = sc.next();
boolean correct = true;
do {
if (acno.length() != 8) {
correct = false;
System.out.println("Account number should be 14 digit long!");
System.out.println("Try again");
System.out.println("Enter your account number: ");
acno = sc.next();
}
} while (!correct);
System.out.println("Enter your PIN: ");
String pass = sc.next();
do {
if (pass.length() != 4) {
System.out.println("Your PIN should be 4 digit long");
System.out.println("Try again");
System.out.println("Enter your PIN: ");
pass = sc.next();
}
} while (pass.length() != 4);
if (accountCredentials.containsKey(acno) && accountCredentials.get(acno).equals(pass)) {
System.out.println("loggedIn successful");
loggedIn = false;
return acno;
} else {
System.out.println("Incorrect account number or PIN");
System.out.println("Try again");
}
} while (!loggedIn);
return null;
}
public void addFunds(Scanner sc, String accNo) {
System.out.println("Enter the amount you want to deposit: ");
int amount = sc.nextInt();
if (amount >= 0) {
accountBalance.put(accNo, accountBalance.get(accNo) + amount);
System.out.println("Deposit successful");
System.out.println("Your new balance is: " + accountBalance.get(accNo));
}
}
public void withdrawFunds(Scanner sc, String accNo) {
System.out.println("Enter the amount you want to withdraw: ");
int amount = sc.nextInt();
if(accountBalance.get(accNo) >= amount) {
accountBalance.put(accNo, accountBalance.get(accNo) - amount);
System.out.println("Withdrawal successful");
System.out.println("Your new balance is: " + accountBalance.get(accNo));
} else {
System.out.println("Insufficient balance");
}
}
public void checkBalance(Scanner sc,String accNo) {
System.out.println("Your current balance is: " + accountBalance.get(accNo));
}
public void changePin(Scanner sc, String accNo) {
System.out.println("Enter your current PIN: ");
String pass = sc.next();
System.out.println("Enter new password: ");
String newpass = sc.next();
accountCredentials.put(pass, newpass);
System.out.println("Password updated successfully :)");
}
}