import java.text.*; import java.util.*; /** * Student Class */ class Student { public String firstName; public String lastName; public String major; public String creditsEarned; public String gradePointAverage; private static final int NUMBEROFFIELDS = 5; /** * Constructor that creates a student from a line read from a tab delimited file */ Student(String inputLine) throws ParseException { StringTokenizer tokenizer = new StringTokenizer(inputLine, "\t"); // create a tokenizer based on tabs // // first check to see if the number of fields is correct // if(tokenizer.countTokens() < NUMBEROFFIELDS) { throw(new ParseException("Invalid Student input line ["+inputLine+"]", 0)); } // // now parse out each field and store in the object's attributes // try{ firstName = tokenizer.nextToken(); lastName = tokenizer.nextToken(); major = tokenizer.nextToken(); creditsEarned = tokenizer.nextToken(); // credits in string format gradePointAverage = tokenizer.nextToken(); // gpa in string format } catch(NoSuchElementException e) { throw(new ParseException("Invalid Student input line ["+inputLine+"]", 0)); } } } // end of the Student Class