A sample question for labtest 2

Phase 1

Create an instance of a University that is randomly generated using the appropriate method (Hint: see API of the class University which is part of the labtest package). Print all the students of the generated University.

Here is a sample run:

7258991 -- SCIENCE
4787548 -- BUSINESS
6556476 -- ARTS
9980310 -- ARTS
3081836 -- SCIENCE

Phase 2

Next, present the user with the following prompt:
Enter file name:
The entry has to be made on the same line as the prompt. If the file does not exist, then the message File does not exist! has to be printed and the user has to be reprompted until an existing file name is entered. To test your program, you may use the file university.txt with the following content.
Jane,3487465,SCIENCE
John,4568765,ARTS
Janet,4357435,BUSINESS
Jane,3487465,BUSINESS
Here is a sample run:
7258991 -- SCIENCE
4787548 -- BUSINESS
6556476 -- ARTS
9980310 -- ARTS
3081836 -- SCIENCE
Enter file name: bla
File does not exist!
Enter file name: university.txt

Phase 3

Next, read the file line by line. For each line, extract the subject, the number and the name (Hint: use StringTokenizer) and create a corresponding Student object and add it to the University object. For example, add a ScienceStudent object with number 3487465. If a Student object with the same number is already present in the collection of Students, then the Student should not be added and a warning should be printed. (Hint: see API of University.) Note that successful additions do not produce any output.

Here is a sample run:

7258991 -- SCIENCE
4787548 -- BUSINESS
6556476 -- ARTS
9980310 -- ARTS
3081836 -- SCIENCE
Enter file name: bla
File does not exist!
Enter file name: university.txt
Warning: Student with number 3487465 is already present