sorry to post this question here...
Codes for BankDB
public Customers[] readFile(String filename)throws FileNotFoundException
{
scStream = new Scanner(new File(filename));
int record =0;
boolean flag=true;
String bData="";
String name="",accID1="",accBal1="",phone="",address="",dob="",accType="",rate1="";
double accBal=0.0, rate=0.0;
int accID=0;
try
{
if (scStream == null )
{
System.out.println("NOT FILE OPENED");
return null;
}
else
{
while (scStream.hasNext())
{
bData=scStream.nextLine();
if(bData.startsWith("Account Id"))
{
accID1=bData.substring((2+ (bData.indexOf("= "))));
accID=Integer.parseInt(accID1);
flag = checkAcc(accID);
if (flag==false)
{
builder.append("Acc ID:"+accID+" has already being created\n");
}
}
else if(bData.startsWith("Name"))
{
name=bData.substring((2+ bData.indexOf("= ")));
if (name.length()>20)
{
flag =false;
builder.append("The name: "+name+" exceed the 20 character words limit\n");
}
}
else if(bData.startsWith("Address"))
{
address=bData.substring((2+ bData.indexOf("= ")));
if (address.length()>80)
{
flag =false;
builder.append("the address: "+address+" exceeed the 80 characters limit\n");
}
}
else if(bData.startsWith("DOB"))
{
dob=bData.substring((2+ bData.indexOf("= ")));
if (dob.length()>10)
{
flag =false;
builder.append("the DOB: "+dob+"exceed the 10 characters limit\n");
}
}
else if(bData.startsWith("Phone Number"))
{
phone=bData.substring((2+ bData.indexOf("= ")));
if (phone.length()>8)
{
flag =false;
builder.append("the phone: "+phone+"exceed the 8 characters limit\n");
}
}
else if(bData.startsWith("Account Balance"))
{
accBal1=bData.substring((2+ bData.indexOf("= ")));
accBal=Double.parseDouble(accBal1);
}
else if(bData.startsWith("Account Type"))
{
accType=bData.substring((2+bData.indexOf("= ")));
if (accType.equalsIgnoreCase("Saving"))
{
if (flag==true)
{
custTemp[index]=new Account1(accID,name.toUpperCase(),address,dob,phone,accBal,accType);
index++;
record++;
}
else
{
System.out.println(builder.toString());
}
}
else if (accType.equalsIgnoreCase("checking"))
{
if (flag==true)
{
custTemp [index]= new Account2(accID, name.toUpperCase(),address, dob,phone, accBal,accType);
index++;
record++;
}
else
{
System.out.println(builder.toString());
}
}
}
else if (bData.startsWith("Fixed Daily Interest"))
{
rate1=bData.substring((2+bData.indexOf("= ")));
rate =Double.parseDouble(rate1);
if (flag==true)
{
custTemp [index]= new Account3(accID, name.toUpperCase(),address, dob,phone, accBal,accType,rate);
index++;
record++;
}
else
{
System.out.println(builder.toString());
}
}
}
}
}
catch (Exception e)
{
System.out.println("Error reading file...." +e.getMessage());
}
System.out.println(record + " records read");
return custTemp;
}
Main class codes frag
public static void main(String[] args)
{
double new_interest=0.0;
BankDB custData = new BankDB();
Scanner input = new Scanner (System.in);
int accID=0;
int index=0;
String fileName="";
char userInput='0';
while (true)
{
System.out.println("First Bank Customer Query System..");
System.out.println("==================================");
System.out.println("(1) Input Data from text file");
System.out.println("(2) Print out Customer Info onto console");
System.out.println("(3) Write Customer Info to a text file");
System.out.println("(4) Delete data");
System.out.println("(5) Update account");
System.out.println("(Q) Quit the system");
System.out.println("Your choice:");
userInput=input.next().charAt(0);
try
{
switch(userInput)
{
case '1':
String[] tempNames=new String [30];
System.out.println("Please enter filename:");
fileName= input.next();
custTemp=custData.readFile(fileName);
for(int i=0; i<custTemp.length;i++)
{
tempNames[i]=custTemp[i].get_name();
}
Arrays.sort(tempNames);
custTxt.clear();
for(int j=0;j<tempNames.length;j++)
{
for (int i=0; i<custTemp.length;i++)
{
if(tempNames[j].equalsIgnoreCase(custTemp[i].get_name()))
{
custTxt.add(j,custTemp[i]);
}
}
}
break;
what these codes is supposed to do is get some data from a text file and put them into an user define type array, sort them into alphabetical order and lastly insert them into an ArrayList...
my logic error faced is that when i do
System.out.println(custTxt.get(1).print());
the contain is empty.. but if i do this instead:
System.out.println(custTemp[1].print());
there are values printed out.. need help on how to solve this...
thx