BankAccountSystem
BankAccountSystem
*;
public class BankAccoutSystem{
public static void main(String[]args){
Scanner s = new Scanner(System.in);
while(true){
System.out.println("\n"+"=".repeat(37));
System.out.println("Simple Bank Account Management System");
System.out.println("=".repeat(37));
System.out.println("1.Log In Account");
System.out.println("2.Create Account");
System.out.println("3.Exit");
System.out.print("Enter your choice(1-3): ");
choice = s.nextLine();
if(choice.equals("1")){
System.out.print("Enter user Name: ");
name = s.nextLine();
System.out.print("Enter user Pin: ");
password = s.nextLine();
if(log_in){
System.out.println("Log in successfully!");
}else{
System.out.println("Can't find account!");
continue;
}
while(log_in){
try{
System.out.println("\n"+"=".repeat(25));
System.out.println("1.Check Account Balance");
System.out.println("2.Deposit");
System.out.println("3.Withdraw");
System.out.println("4.Log out Account");
System.out.print("Enter your choice: ");
choice = s.nextLine();
if(choice.equals("4")){
System.out.println("Account successfully logged out.");
log_in = false;
break;
}
if(choice.equals("1")){
System.out.println("Your account balance is $" +
balance[loggedAccount]);
continue;
}else if(choice.equals("2")){
System.out.print("Enter amount you want to deposit: ");
double amountDeposit = s.nextDouble();
s.nextLine();
if(amountDeposit < 1){
System.out.println("Invalid Amount!");
continue;
}else{
System.out.println("$" + amountDeposit + "
Successfully Deposited!");
balance[loggedAccount] += amountDeposit;
continue;
}
}else if(choice.equals("3")){
System.out.print("Enter amount you want to withdraw:
");
double amountWithdraw = s.nextDouble();
s.nextLine();
if(amountWithdraw > balance[loggedAccount]){
System.out.println("Insufficient Balance!");
continue;
}else if(amountWithdraw < 1){
System.out.println("Invalid Amount!");
}else{
System.out.println("$" + amountWithdraw + "
Successfully Withdrawn!");
balance[loggedAccount] -= amountWithdraw;
continue;
}
}else{
System.out.println("Invalid Input!");
continue;
}
}catch(Exception e){
System.out.println("Invalid Input!");
s.nextLine();
continue;
}
}
}else if(choice.equals("2")){
if(accIndexcount < Accounts.length){
System.out.println("\n"+"=".repeat(25));
System.out.print("Enter Account Name: ");
String newName = s.nextLine();
String newPin;
while(true){
System.out.print("Enter Account Pin: ");
newPin = s.nextLine();
if(newPin.matches("\\d{4}")){
break;
}else{
System.out.println("\nInvalid PIN! Please enter 4
digits Pin.");
}
}
Accounts[accIndexcount][0] = newName;
Accounts[accIndexcount][1] = newPin;
accIndexcount++;
}
}
}