I have this assignment where I need to populate a 2d array using info from a text file. I am trying to make every thing even using the primekey variable to replace my poscon that I am using temporarily. What is stopping me from doing that is that primekey wont increment right because of another
(MAIN PROBLEM) variable that is stuck, which is the emailcheck variable. I'm pretty sure it has to do with my for loop syntax but I can't quite figure it out.
...
try{
Scanner check = new Scanner(file);
Scanner checkNext = new Scanner(file);
System.out.println("Success File load");
String data=check.next();
System.out.println("data.next() works");
int emailcheck=0;
int primekey=0;
while(check.hasNext()){
posCon++;
//check for @ symbol
for(int i=0;i<data.length();i++){
if(data.charAt(i)=='@'){
emailcheck=emailcheck+1;
}
}
//populates position array
if(data.equalsIgnoreCase("staff")||
data.equalsIgnoreCase("freshman")||
data.equalsIgnoreCase("sohmore")||
data.equalsIgnoreCase("junior")||
data.equalsIgnoreCase("senior")||
data.equalsIgnoreCase("adjunct")||
data.equalsIgnoreCase("professor"))
{
db[0][posCon]=data;
sort=1;
data=check.next();
}
//id
else if(sort==1){
db[1][posCon]=data;
sort=2;
data=check.next();
}
//firstname
else if(sort==2){
db[2][posCon]=data;
sort=3;
data=check.next();
}
//lastname
else if(sort==3){
db[3][posCon]=data;
sort=4;
data=check.next();
}
//department
else if(sort==4){
db[4][posCon]=data;
sort=5;
data=check.next();
}
//email
else if(sort==5 && emailcheck==1){
db[5][posCon]=data;
sort=6;
emailcheck=0;
}
else if(sort==5 && emailcheck==0){
db[5][posCon]="not here";
sort=6;
}
//room
else if(sort==6){
db[6][posCon]=data;
sort=0;
data=check.next();
emailcheck=0;
primekey=primekey+1;
System.out.println(primekey);
}
else{
sort=0;
data=check.next();
emailcheck=0;
}
}
}catch(FileNotFoundException e) {
e.printStackTrace();
}
}//End Constructor
here is the data from the text file
Staff 77778 Julie Chang Registrar
Adjunct 19778 Mike Thompson CS mtxxx@gmail.com GITC2400
Staff 30041 Anne Mathews Security
Junior 98444 Serene Murray Math smyyy@gmail.com
Freshman 98772 Bob Mathew CS bmyyy@gmail.com
Professor 19010 Joan Berry Math jbxxx@gmail.com GITC2315C
Professor 19871 Aparna Khat CS akxxx@gmail.com GITC1400
Adjunct 18821 Hari Mentor Physics hmxxx@gmail.com CK231
Staff 20112 Jim George Plant
Junior 68339 Tom Harry CS thyyy@gmail.com
Senior 78883 Vince Charles IT vcyyy@gmail.com
Freshman 87777 Susan Han EE shyyy@gmail.com
Senior 88888 Janki Khat IE jkyyy@gmail.com
Staff 5555 Aparna Sen Plant
Senior 66663 Jill Kaley it jk@jk.com
Staff 77777 Joe Batra plumbing
Staff 33333 Jim Natale Plumbing