In: Computer Science
Using Repl.it
In this assignment you will create a Java program that allows a Bank customer to do the following:
1) Create a bank account by supplying a user id and password
.2) Login using their id and password
3) Quit the program.
Now if login was successful the user will be able to do the following:
1) Withdraw money.
2) Deposit money.
3) Request balance.
4) Quit the program.
If login was not successful (for example the id or password did not match) then the user will be taken back to the introduction menu.
This is what your program in action will look like:
Hello
Welcome to Genesis Bank ATM Machine
Please select an option from the menu below:
l -> Login
c -> Create New Account
q -> Quit
> L
Please enter your user id: 12
Please enter your password: 2345
Create an Array List of about 10 Bank customers, basic money transactions for deposit, withdrawal, and balance checking.
package bankapplication;
import java.util.*;
/**
*
* @author mmc
*/
class Account
{
public Account(int anAccountNumber)
{
accountNo = anAccountNumber;
amtbal = 0;
}
public Account(int anAccountNo, double intBalance,String
uname,String pword)
{
accountNo = anAccountNo;
amtbal = intBalance;
username=uname;
password=pword;
}
public int getAccountNumber()
{
return accountNo;
}
public void deposit(double amount)
{
double newBal = amtbal + amount;
amtbal = newBal;
}
public void withdraw(double amount)
{
double newBalance = amtbal - amount;
amtbal = newBalance;
}
public double getBal()
{
return amtbal;
}
boolean checkUserName(String uname,String
pword,ArrayList<Account> al)
{
boolean c=true;
for(int i=0;i<10;i++)
{
Account d=al.get(i);
if(d.username==uname && d.password==pword)
c=true;
else
c=false;
}
return c;
}
private int accountNo;
private double amtbal;
private String username,password;
int n=10;
}
public class BankApplication
{
static int account;
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
ArrayList<Account> accounts = new
ArrayList<Account>();
String uname,pword;
int i;
account=1000;
do
{
System.out.println("Please select from the option");
System.out.println("1.Create Bank account");
System.out.println("2.LOGIN");
System.out.println("3.Exit");
i=s.nextInt();
switch(i)
{
case 1:
System.out.println("Enter username:");
uname=s.nextLine();
System.out.println("Enter password:");
pword=s.nextLine();
i++;
accounts.add(new Account(i,0,uname,pword));
break;
case 2:
boolean check;
System.out.println("Enter UserName");
uname=s.nextLine();
System.out.println("Enter password:");
pword=s.nextLine();
check=accounts.checkUserName(uname,pword,accounts);
if(check==true)
{
int j=0;
do
{
System.out.println("1.Withdraw Money");
System.out.println("2.Deposite MOney");
System.out.println("3.Request Balance");
System.out.println("3.Exit");
System.out.println("Select a option:");
switch(j)
{
case 1:
System.out.println("Enter Amount:");
double am=s.nextInt();
accounts.withdraw(am);
}
}
while(j==3);
break;
}
default:
System.out.println("Select an option");
}
}
while(i==3);
}
}