Project #1
(Arrays, Files, and Reports)
(Due 15 Sept 06)
Some basic information about a group of students from the College of Natural Science & Mathematics has been stored in two files. One file, named living.txt, contains info about where the students live; each line of the file has the following form:
Student_Number Last_name, First_name Dormitory
This is a text file with the Student Number being 6 digits; this is followed by a space. The last name (always one word) is followed by a comma and a space; the first name (always one word) is often followed by many spaces but always at least one. The dormitory is also a single word. This file stores the student's info in alphabetical order.
The second file, named academics.dat, contains information about how the student is doing academically; it is a binary file. For each student, the following information is stored in consecutive bytes:
Student number (4-byte integer); Age (2-byte integer); Number_of_credits (2-byte integer); GPA (32-bit floating point value); and Major (a 4-byte character sequence, such as COSC). Thus, each student's info is represented in 16 bytes in the file; the information is stored in ascending student-number order.
You are to write a Java program that reads in the information from both files and then responds to commands that are entered through the keyboard. The program should prompt the person at the keyboard to enter an 'M' or 'm' for see listings by major; to enter 'D' or 'd' to see listings by dormitory; to enter 'I' or 'i' to see a listing about an individual student; or to enter 'Q' or 'q' to quit. After specifying the type of listing, the person at the keyboard should be asked to specify the name of the Major or Dormitory or the student's number.
For the Major action, the listing should show the Student number, name, number of credits, and GPA for every student in that major.*
For the Dormitory action, the listing should show the Student number, name, age, and major for every student in that dormitory.*
For an individual student, the listing should show all information about that one student.
* There is one exception for the Major and Dormitory listings. If the person at the keyboard, enters "All" instead of a major or dormitory name, a different listing must be produced. For Major, the "All" listing should show the name of every major and the number of students in that major. For Dormitory, the "All" listing should show the name of every dormitory and the number of students who live there.
Here are a couple sample listings: First a listing of students living in Lawrence Hall:
Students living in Lawrence
Student Name
Age Major
215923 Bumstead, Alexander
20 BIOC
217706 Cameron, Toby
22 BIOL
214877 Capp, Andy
18 COSC
216673 Fillmore, Mallard
20 BIOL
219036 Flagston, Lois
19 EOPT
215922 Mitchell, Henry
20 ENVH
213407 Smith, Tina
19 BIOL
219863 Thornapple, Brutus
25 COSC
219404 Tracy, Dick
18 ENVH
214641 Worth, Mary
20 GEOS
Then a listing of all information about one student (Mary Worth, 214641):
Student number: 214641
Student Name
Dorm Major Age Credits
GPA
214641 Worth, Mary
Lawrence GEOS 20
49 3.52
Finally, a listing of the counts of students by major:
Which major? All
Major No.Students
MAED
8
CHEM
7
BIOL 17
PHYS
9
MATH 10
ENVH 15
BIOC
7
EOPT 15
COSC 14
GEOS
7
NMTT 11
Both living.txt and academics.dat can be found in the folder I:/jlwolfe/310. Requirement: you must create at least one interface for interacting with the person at the keyboard (Chapter 1 provides a model). The class which implements the interface (and others) will be changed when you do project #2.
Hand in the following materials:
a printout of all interfaces, classes and methods you created to do this
project and a printout showing the responses to several commands which
I will specify three days before the project is due. Copy all .java
files you made to your folder on the P drive for COSC 310.