I have a text file which contains a student number (9 digits), pin (4 digits), first name, last name. Which looks like this:
456864324,4965,Eves,Dalton
457642455,2164,Jagger,Michael
132435465, 3578,McIvar, Alan
543247531,2854,Jones, Alan
The student enters its student number and then pin. The program matches his input to the text file and checks if it matches or not.
So far I've separated the text line by line and stored it into an ArrayList and then thought about splitting it with ",". I've also thought about using Maps but cannot figure out how I will store the names with it as well.
String studentdb = sn_field.getText(); //get student number from input
String pindb = pin_field.getText(); //get pin from input
try {
File f = new File("file name");
Scanner sc = new Scanner(f);
ArrayList<String> number= new ArrayList<String>();
ArrayList<String> pswd = new ArrayList<String>();
while(sc.hasNextLine()){
String line = sc.nextLine();
// = line.split("\n");
String sn = line;
people.add(sn);
}
//if(people.contains(studentdb)){
//System.out.println("pass");}
} catch (FileNotFoundException f) {
System.out.print("file not found");
}
All in all if the student number and pin both are wrong, it should give an error, if both are correct and match, it passes. Any help would be appreciated as I'm just a beginner at Java.