import java.util.Scanner;
public class OpenBank {
static int count = 0;
public static void main(String[] args) {
char op;
System.out.println("************ Welcome to Funny Bank *********");
do{
Scanner sc = new Scanner(System.in);
System.out.println("---------------------------------------");
System.out.println("1.Open new account");
System.out.println("2.Log in");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
//java not support consicutive int,string input(as problem of press enterkey)
//so,I take below line to hold enterkey
sc.nextLine();
if (choice == 1) {
System.out.print("Enter your name:");
String name = sc.nextLine();
System.out.print("Enter mobile number: ");
String mob = sc.nextLine();
System.out.print("Set userID: ");
String id = sc.nextLine();
System.out.print("Set password: ");
String pass = sc.nextLine();
Customer cust = new Customer(name, mob, id, pass);
cust.addCustomer(cust);
count++;
} else if(choice == 2){
if(count == 0){
System.out.println("Sorry! you are the first customer.Please open new account");
continue;
}
System.out.print("Enter userId:");
String id = sc.nextLine();
System.out.print("Enter password: ");
String pass = sc.nextLine();
Customer.checkValidate(id, pass, count);
if(Customer.checkValidate(id, pass, count)){
System.out.println("Log in success!");
Customer.showDetails();
int choose;
do{
System.out.println("\t1.Diposite Money");
System.out.println("\t2.Withdraw money");
System.out.println("\t3.Log out");
System.out.print("choose: ");
choose = sc.nextInt();
sc.nextLine();
if(choose == 1){
System.out.print("Enter amount to add your account:");
double amount = sc.nextDouble();
sc.nextLine();
Customer.addBal(amount);
Customer.showDetails();
} else if(choose == 2){
System.out.print("Enter amount to withdraw: ");
double amount = sc.nextDouble();
sc.nextLine();
Customer.withdraw(amount);
Customer.showDetails();
}
}while(choose !=3);
} else { System.out.println("Login fail..............");}
}
} while(true);
}
}
import java.util.ArrayList;
public class Customer {
static ArrayList <Customer> list = new ArrayList<>();
private String name;
private String mobNumber;
private String userId;
private String password;
private double bal;
public Customer(String name, String mobNumber,String id,String pass){
this.name = name;
this.mobNumber = mobNumber;
this.userId = id;
this.password = pass;
this.bal =0;
}
public String getName(){
return this.name;
}
public String getMob(){
return this.mobNumber;
}
public String getId() {
return this.userId ;
}
public String getPass(){
return this.password;
}
public double getAmount(){
return this.bal;
}
public void updateAmount(double money){
this.bal += money;
}
//ADDING CUSTOMER TO THE ARRAY LIST
public void addCustomer(Customer C){
list.add(C);
}
static int i = 0; // THIS i INDICATE THE CURRENT VERIFIED CUSTOMER INDEX NO.
//CHECKING USER_ID AND PASSOWRD WITH THE AVAILABLE LIST
public static boolean checkValidate(String id, String pass,int count){
for (i =0;i<count;i++){
// System.out.println(list.get(i).getId() +" "+list.get(i).getPass());
// list.get(i).getId();list.get(i).getPass();
if(id.equals(list.get(i).getId()) && pass.equals(list.get(i).getPass()) ){
return true;
}
}
return false;
}
public static void showDetails(){
System.out.println("-------------------------------------------------------------------------------");
System.out.println("Name: "+list.get(i).getName()+"\tMob: "+list.get(i).getMob()+"\tUserID: "+list.get(i).getId() +"\tPassW: "+list.get(i).getPass()+"\tBal: "+list.get(i).getAmount());
System.out.println("-------------------------------------------------------------------------------");
}
public static void addBal(double money){
list.get(i).updateAmount(money);
}
public static void withdraw(double money){
if(list.get(i).getAmount() < money){
System.out.println("\tSorry! low balence");
return;
}
list.get(i).updateAmount(-money);
}
}