I'm working on a project for school where we have to read from a voters database which is set up in the following manner:
voternumber:voternama:havevoted
Ex:
1253:Bill Simmons:false
3244:Steve Jobs:true
I made this algorithm to search for a voter by ID number but for some reason it keeps coming up as not found. I've been looking at it for awhile.. maybe fresh eyes can spot the problem?
FileInputStream test = new FileInputStream("backupvoters.txt");
Scanner testinput = new Scanner(test);
int found = 0;
String next [] = new String[3], temp = "";
while(found == 0)
{
try
{
temp = testinput.nextLine();
}
catch(NoSuchElementException exitloop)
{
found = 5;
}
next = temp.split(":");
if(next[0] == ID)
{
found = 1;
}
}
if(found == 1 && next[3] != "true")
{
JFrame hello = new JFrame("Confirmed!");
JLabel a = new JLabel("Welcome " + next[2] + "!");
hello.add(a);
int r = 0;
while(r < allBallots.length)
{
allBallots[r].enableButtons();
r++;
}
hello.setBounds(100, 100, 500, 100);
hello.setVisible(true);
}
else if(found == 1)
{
JFrame hello = new JFrame("Already voted");
JLabel a = new JLabel(next[2] + " you already voted!");
hello.add(a);
hello.setBounds(100, 100, 500, 100);
hello.setVisible(true);
}
else
{
JFrame noname = new JFrame("Not found");
JLabel a = new JLabel("Your ID was not found.");
noname.add(a);
noname.setBounds(100, 100, 500, 100);
noname.setVisible(true);
}