/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bank;
import java.io.*;
import java.util.*;
public class accountList {
private List accountlists = new LinkedList();
public void addAccount(bankAccount a1)
{
accountlists.add(a1);
}
public int searchAccountNumber()
{
int max = 1000;
if(accountlists == null)
return max;
for(Iterator iterator = accountlists.iterator(); iterator.hasNext()
{
bankAccount a1 = (bankAccount) iterator.next();
if(a1.getAccNumber() > max)
max = a1.getAccNumber();
}
return max;
}
public boolean searchAccountNumber(int acc)
{
for(Iterator iterator = accountlists.iterator(); iterator.hasNext()
{
bankAccount a1 = (bankAccount) iterator.next();
if(a1.getAccNumber() == acc)
return true;
}
return false;
}
public bankAccount searchAccount(int acc)
{
for(Iterator iterator = accountlists.iterator(); iterator.hasNext()
{
bankAccount a1 = (bankAccount) iterator.next();
while(a1.getAccNumber() == acc)
return a1;
}
return null;
}
public void display()
{
for(Iterator iterator = accountlists.iterator(); iterator.hasNext()
{
bankAccount a1 = (bankAccount) iterator.next();
if(a1.equals(null))
System.out.println("No any accounts.");
else
System.out.println(a1);
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bank;
public class bankAccount {
private String name;
private int accountnumber;
private double balance;
private transactionsList accountTrans = new transactionsList();
public bankAccount(String n, int account, double balance)
{
name = n;
this.balance = balance;
accountnumber = account;
}
public String toString()
{
String str = accountnumber + " " + name + " " + balance;
return str;
}
public double getBalance()
{
return balance;
}
public String getName()
{
return name;
}
public int getAccNumber()
{
return accountnumber;
}
public void deposit(double a)
{
balance += a;
}
public void withdrawl(double a)
{
balance -= a;
}
public void addTrans(transactions t)
{
accountTrans.addtransactions(t);
}
public void display()
{
accountTrans.displayAll();
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bank;
import java.io.*;
import java.util.*;
public class Main {
private static Scanner keyboard = new Scanner(System.in);
private static accountList alist = new accountList();
public static void main(String[] args) {
int choice;
{
menu();
choice = keyboard.nextInt();
switch(choice)
{
case 1: addAccount();
break;
case 2: displayAccounts();
break;
case 3: login();
break;
case 4: System.exit(0);
}
}while(choice != 4);
System.out.println("Thanks for using");
}
public static void menu()
{
System.out.println("1. Add account.");
System.out.println("2. Display all accounts.");
System.out.println("3. Login Accounts.");
System.out.println("4. Exit System.");
System.out.print("Pleae enter your choice(1- 4): ");
}
public static void submenu()
{
System.out.println("1. Deposit.");
System.out.println("2. Withdrawl.");
System.out.println("3. Show All transactions.");
System.out.println("4. LogoutAccount.");
System.out.print("Pleae enter your choice(1- 4): ");
}
public static void addAccount()
{
String name;
Scanner keyboard3 = new Scanner(System.in);
System.out.print("Please enter your first name: ");
name = keyboard3.nextLine();
bankAccount account = new bankAccount(name, alist.searchAccountNumber()+1, 0);
alist.addAccount(account);
}
public static void displayAccounts()
{
alist.display();
}
public static void login()
{
int acc, choice;
boolean check;
do
{
System.out.print("Please enter you account number: ");
acc = keyboard.nextInt();
check = alist.searchAccountNumber(acc);
if(check != true)
System.out.println("Unable to locate account.");
}while(check != true);
bankAccount account = alist.searchAccount(acc);
if(account != null)
{
do
{
System.out.println("Current Balance = " + account.getBalance());
submenu();
choice = keyboard.nextInt();
switch(choice)
{
case 1: deposit(account);
break;
case 2: withdrawl(account);
break;
case 3: showAllTrans(account);
break;
case 4: return;
}
}while(choice != 4);
}
}
public static void deposit(bankAccount acc)
{
double amount;
System.out.print("Enter the amount: ");
amount = keyboard.nextDouble();
acc.deposit(amount);
transactions t1 = new transactions(acc.getBalance(), amount, "+");
acc.addTrans(t1);
}
public static void withdrawl(bankAccount acc)
{
double amount;
do
{
System.out.print("Enter the amount: ");
amount = keyboard.nextDouble();
if(acc.getBalance() <= amount)
System.out.println("Low balance.");
}while(acc.getBalance() <= amount);
acc.withdrawl(amount);
transactions t1 = new transactions(acc.getBalance(), amount, "-");
acc.addTrans(t1);
}
public static void showAllTrans(bankAccount acc)
{
acc.display();
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bank;
import java.util.*;
public class transactions {
private double balance;
private double withdrawlordeposit;
private String plusminus;
//private String date;
public transactions(double bal, double wd, String pm)
{
balance = bal;
withdrawlordeposit = wd;
plusminus = pm;
}
public String toString()
{
String str = plusminus + withdrawlordeposit + " " + balance;
return str;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bank;
import java.util.*;
public class transactions {
private double balance;
private double withdrawlordeposit;
private String plusminus;
//private String date;
public transactions(double bal, double wd, String pm)
{
balance = bal;
withdrawlordeposit = wd;
plusminus = pm;
}
public String toString()
{
String str = plusminus + withdrawlordeposit + " " + balance;
return str;
}
}
//can anybody figure out whats wrong here. Its not a syntax error at all. The program runs but when i tried to add new account and enter the first name which the program will ask for. It just gets stuck at there.
Don't know whats wrong. Can anyone help. Thanks