Hi All
I have been stuck on this for a number of hours now, really cant workout how I should go about making this work, I am not looking for the correct code, More looking for what I should be looking up and what I have done wrong.
What the code should be doing is scanning a file, Looking at the first token of a line, and matching it to a what the user input, if the token matches, print the whole line and move onto the next line, and so on...
Here is the code I have mustered up so far
public class ExamTimes {
public void printCourse(){
Scanner sc = new Scanner(System.in);
System.out.print("Enter the course code: ");
String userInput = sc.next();
try {
BufferedReader input = new BufferedReader(new FileReader("examdata.txt"));
String strData = (input.readLine());
while ((strData = (userInput())) != null) {
StringTokenizer Tok = new StringTokenizer(strData);
String compare = Tok.nextToken();
if (compare.equals(userInput)){
System.out.println(compare);
}
}
input.close();
} catch (IOException e) {
}
And here is a sample of what examdata.txt looks like,
ACCY111 KKLT301 10 50 PEDERSEN REID
ACCY111 KKLT303 10 85 REID SKINNER
ACCY111 MCLT101 10 82 SKINNER THAM
ACCY111 MCLT102 10 39 THEVAKULASINGAM VANN
ACCY111 MCLT103 10 84 VEGAR XU
ACCY111 RHLT2 10 26 YANG ZHU
ANTH102 EALT006 22 72 ABRAHAM GIANNOTTI
ANTH102 EALT206 22 25 GIBSON JENKINS
ANTH102 KKLT301 22 50 JOBBINS OAKLEY
ANTH102 KKLT303 22 84 OATES WOOTTON
ARCH172 MCLT101 20 82 ANDERSON LEE
ARCH172 MCLT103 20 83 LI ZHAO
ARCH251 VS127 2 12 ABRAHAM COCKROFT
ARCH251 VS220 2 12 CRABBE GILLER
ARCH251 VS308 2 16 GLEN KIMBER
So expanding on what I was trying to explain above, When the user types in "ACCY111" I would like it to print the following section of text
ACCY111 KKLT301 10 50 PEDERSEN REID
ACCY111 KKLT303 10 85 REID SKINNER
ACCY111 MCLT101 10 82 SKINNER THAM
ACCY111 MCLT102 10 39 THEVAKULASINGAM VANN
ACCY111 MCLT103 10 84 VEGAR XU
ACCY111 RHLT2 10 26 YANG ZHU
Thoughts please?