-
re: code only includes first person to datastructure , why?
Please help as the code seems logical to me.
But only the first person gets added to database.
why?????
import java.io.*;
class TestBankRecord {
public static void main(String ar[] ) {
int DATABASE_LENGTH =100;
BankRecord[] database = new BankRecord[DATABASE_LENGTH];
BankRecord bankrecord = new BankRecord();
bankrecord.setUserID( "w110");
// will add cusotmer to database if at first position of array or
does
// not exist in array
int i = 0;
int j = database.length;
while ( i < j )
{
if (database[i] == null)
{ database[i] = bankrecord;
i = database.length ; //break out of the loop termination
has ended
}
else if ( database[i].getUserID().equals(bankrecord.getUserID())
)
{} // do not add customer to database as it already exists
else
{ //the customer is not in database so add it to position
database[i+1] = bankrecord; //customer is not in database
so add it to next position in database
i = database.length; //break out of loop.
}
i++;
}
//adding person 2
bankrecord = new BankRecord(); //person2
bankrecord.setUserID( "w119");
while ( i < j )
{
if (database[i] == null)
{ database[i] = bankrecord;
i = database.length -1; //break out of the loop termination
has ended
}
if ( database[i].getUserID().equals(bankrecord.getUserID()) ==
true )
{ } // do not add customer to database as it already exists
if ( database[i].getUserID().equals(bankrecord.getUserID()) ==
false )
{ //the customer is not in database so add it to position
database[i+1] = bankrecord; //customer is not in database
so add it to next position in database
i = database.length; //break out of loop.
}
i++;
}
System.out.println("Testing databse UserID : " + database[0].getUserID()
);
System.out.println("Testing databse UserID : " + database[1].getUserID()
);
}
}
public class BankRecord{
private String userID;
public BankRecord()
{}
public void setUserID(String userID) { this.userID = userID; }
public String getUserID() { return userID; }
}
please help have tried many ways the code seems logical enougth to me but
it doesn't work.
Need urgent help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks