oh no..i forgot to put the code tags..
here is my improved program..the thing in bold is the suggested correction.
import corejava.Console;
/****************************************************************
**cLASS bANKaCCOUNT REPRESENTING THE RUN-TIME MULTI-USER SYSTEM**
****************************************************************/
public class BankAccount
{
/****************************
**DATA OF bANKaCCOUNT CLASS**
****************************/
private static final int MAXACC=10;
private static int acc_logged_in;
private static int no_acc_created;
private static Account[] database;
/*******************************
**METHODS OF bANKaCCOUNT CLASS**
*******************************/
// initialisation block
{
acc_logged_in=-1;
no_acc_created=0;
database=new Account[MAXACC];
[B]for(int i=0;i<MAXACC;i++)
database[i]=new Account();
[/B] }
private static void createnew()
{
String str;
no_acc_created++;
acc_logged_in=no_acc_created;
str=Console.readLine("\nEnter your name : ");
database[acc_logged_in].SETname(str);
database[acc_logged_in].SETbalance(Console.readInt("Enter your initial balance : "));
database[acc_logged_in].SETaccountid((int)(Math.random()*32000));
System.out.println("Your account I.D. is " + database[acc_logged_in].GETaccountid());
System.out.println("Account created successfully...\n\n");
}
private static void login()
{
int i,no;
boolean found=false;
no=Console.readInt("\nEnter your account I.D. : ");
for(i=0;i<no_acc_created;i++)
{
if(no==database[i].GETaccountid())
{
acc_logged_in=i;
found=true;
break;
}
}
if(found==true)
System.out.println("Logged in successfully as " + database[acc_logged_in].GETname() + "...\n\n");
else
System.out.println("Error : The I.D. did not match with any of the accounts !\n\n");
}
private static void logoff()
{
if(acc_logged_in==-1)
{
System.out.println("\nNo account is currently logged in !\n\n");
}
else
{
acc_logged_in=-1;
System.out.println("\nLogged off your account successfully...\n\n");
}
}
private static int menu()
{
int choice;
System.out.println("\n\t\tBANK-ACCOUNT");
System.out.println("\t\t~~~~~~~~~~~~");
System.out.println("");
System.out.println("\t<1> Create new account");
System.out.println("\t<2> Log in your account");
System.out.println("\t<3> Log off your account");
System.out.println("\t<4> View current status");
System.out.println("\t<5> Deposit an amount");
System.out.println("\t<6> Withdraw an amount");
System.out.println("\t<7> Exit BankAccount.java");
do
{
choice=Console.readInt("\n\t\tEnter your choice (1 to 7): ");
}
while(choice<1||choice >7);
return choice;
}
public static void main(String[] args)
{
int choice;
boolean …