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

BankAccountSystem

The document is a Java program that implements a simple bank account management system allowing users to log in, create accounts, check balances, deposit, and withdraw funds. It manages up to five accounts with basic validation for account creation and transactions. The program runs in a loop until the user chooses to exit, handling user inputs and exceptions appropriately.

Uploaded by

nacanielbugsag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

BankAccountSystem

The document is a Java program that implements a simple bank account management system allowing users to log in, create accounts, check balances, deposit, and withdraw funds. It manages up to five accounts with basic validation for account creation and transactions. The program runs in a loop until the user chooses to exit, handling user inputs and exceptions appropriately.

Uploaded by

nacanielbugsag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

*;
public class BankAccoutSystem{
public static void main(String[]args){
Scanner s = new Scanner(System.in);

String[][]Accounts = new String[5][2];


double[]balance = new double[5];
String password, choice, name;
int accIndexcount = 0;

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();

boolean log_in = false;


int loggedAccount = -1;

for(int i = 0; i < accIndexcount; i++){


if(Accounts[i][0].equals(name) && Accounts[i]
[1].equals(password)){
log_in = true;
loggedAccount = i;
break;
}
}

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++;

System.out.println("\nAccount successfully created.");


System.out.println("Account Name: " + newName + "\nAccount Pin:
" + newPin);
continue;
}else{
System.out.println("Account Storage is Full.");
continue;
}
}else if(choice.equals("3")){
System.out.println("Thank you, Goodbye!");
s.close();
break;
}else{
System.out.println("Invalid Input!");
continue;
}

}
}
}

You might also like