CSE142 Spring 2004
Assignment 3
University Data Base
Due Dates: see below
In this assignment you will explore the use of loops and conditionals
to analyze information that would be difficult to analyze by
hand.
The Exposition covers some basics of getting ready to do this
assignment.
In Part 1, you develop a system to extract information from a
database
of students. In Part 2, you extend the system to answer
more sophisticated questions about the data.
Exposition
In order to develop an application capable of analyzing data, first
get some data! Luckily, we provide you with such a data source.
The data consists of information about students over many years at a
university. To get
started, download Registrar.class, StudentData.class, and BasicClassList.class and put them
in the
folder where you are going to put your new .java files (you can create
a new folder if you want). These files are .class files; they're what
gets made when .java files are compiled. You will not be able to
view them in any comprehensible form.
Now fire up DrJava. The following steps are suggested as a
way of making sure you are in the right directory. The point is
to create a file called ClassListAnalyzer.java, which is one of the
class you will write. It MUST be in the same directory as where
you put the three files downloaded above.
Click the 'New' button to create a new file.
Now click 'Save'.
When Save box comes up, look for a drop down box that
is labeled 'Files of Type'
and make sure 'All Files' or
'*' is selected.
Now find the folder where you put the files you downloaded above.
In the 'FileName' field type 'ClassListAnalyzer'
(no quotes,
and case is important!).
Click OK and then click the 'Compile All'
button.
The empty file should compile without any problems, if it
doesn't, get help. Now in the interactions pane type:
BasicClassList myList = new BasicClassList(1920);
If it works, great! If you get an error, DON'T GO ANY FURTHER!
Go back and reread the instructions, or ask for help. You won't be able
to do any of the rest of the assignment without this working.
OK, so now you have the .class files installed properly, let's see what
can be done with them.
Since you don't have the source code for these libraries you
can't simply look at the code to find the available methods.
... Never fear! ... All good programmers provide clear
documentation for their
code. Go browse the
documentation now, take some time to get familiar
with it.
To be sure you understand it, try a few things out and answer the
following questions in a file called exposition.txt.
- In the interactions pane create a new instance of the
BasicClassList class for the year
1880. Use the
getNextStudent method of
your
instance to retrieve the first StudentData
object. What is that student's name, major, and GPA?
- In total, how many students are there in year 1880? Which
one has the highest GPA?
- Having seen all the 1880 students, what can you type to get back
to the first one (without
creating a new BasicClassList object).
- Use the documentation to find out what are the earliest and
latest years for which there are student records. Who is the
first student of that last year? Has that person graduated?
What do you get when you try a year which is outside that range?
- What does the compareTo method do?
Try it out! (Hint: you'll need at least two pieces of student
data to use this. . .)
- The String class has a compareTo method as well. Try it
out. What if you wanted to compare two strings without case
sensitivity? How would you do that?
Development
Electronic due Wednesday, April 28 at 10pm (ClassListAnalyzer.java
and exposition.txt). Paperwork is due in class the next day.
The StudentData class is fine if only information
about
individual students is needed, but another class is needed to find out
about
larger groups of students. Your task is to write (and test to be sure
it
works properly!) a class called ClassListAnalyzer
that has the following characteristics:
- A constructor that takes the desired year to be analyzed.
- A method printRoster that takes
no arguments and prints out every student in the list (see footnote).
- A method meanGPA that returns
the mean GPA of class list as a double.
- A method minGPA
that returns a StudentData object
corresponding to the student with the lowest GPA.
- A method maxGPA that returns a
StudentData object corresponding to the
student with the highest GPA.
In all the code you write, aim to not rewrite code you've already
written. If you find yourself writing code to do the same or a
similar
thing in several places, consider making a method to perform that
behavior.
Discuss with your partner how the code differs.
Try to figure out if you could use a parameter to handle it.
Recapitulation
Electronic due Sunday, May 2 at 10pm (the revised version of
ClassListAnalyzer, DataPortal, and coda.txt). Paperwork is
due in class the next day. Turn in your cadenza paragraph as well. Be
sure
to put your quiz section on your paper.
Add a few more methods to your ClassListAnalyzer
class. Continue being careful to not repeat code ...
instead, reuse methods.
- A method printHonorRole that takes
a double (GPA) and prints out the record for every student
with
a GPA the same as or higher than the specified GPA (see footnote).
4/30/2004: The spelling of the
method name printHonorRole should have been printHonorRoll. But
please stick with the original spelling, printHonorRole. Of
course, you could add an additional method named printHonorRoll and
just call one of the two methods from the other.
- A method rangeInMajor that takes
a String (major) and prints out the highest and
lowest GPA in that major. Output should be in this form:
min: 1.8
max: 3.9
Now that you have a tool for analyzing class lists from a
particular year, it would be beneficial to have a way to investigate
many
years at once. Moreover, it would be nice to have a simple way
for a user who is not a programmer to communicate with the system.
Remember,
keep code
duplication to an absolute minimum (it is often good to create new
methods!).
To handle multiple values, write a new class DataPortal
with the following characteristics:
- A method meanGPA that takes no
parameters and returns the mean GPA over a range of years. 4/30/2004:
Definition of "the mean over a range years": the mean of the
means of the individual years. That is, to compute it, you find
the mean for each year, separately, and take the mean of those
numbers. There is no weighting to take into account the number of
students in a year. This number ("the mean of the means") is not
necessarily the number you would get if you added up the GPAs of all
the individual students in all the years and then divided by the number
of students.
The method prompts the user with two dialog boxes (use the input
package) into each of which (s)he can enter a year.
You need to make sure the user can put in the years in any order.
Return a value of 0.0 for an invalid range, e.g., between -50 and -10.
- A method printStudentHistory that
takes
no parameters, prompts the user for a first name then a last name, and
prints out every record for that student from any year. The name
comparison should not be case sensitive. (Also see footnote).
4/30/2004: Because of the way
the uwcse.io.Input class work, a user may not be able to properly enter
a name which has more than one part (for example, a last name like "La
Zander", or a given name like "Alan C. Y."). Don't let that upset
you. You don't need to provide a work-around or do anything
special in your code. We will only test your program using
single-word first and last names. If you can find students with
simple names, you are fine. Along the same lines, you don't need
to give "first name" any special interpretation. The value
returned by getGivenNames can be considered the first name, no matter
what form it has. You are not expected to try to separate or
remove initials, etc.
Coda
Discuss the following questions with you partner and answer them in a
file called coda.txt.
- What are some reasons for wanting to minimize writing duplicated
code?
- ClassListAnalyzer and DataPortal both help answer questions about
our student data.
What are some reasons why they are two separate
classes instead on one big class?
- In general, why do we write several smaller classes instead of
one big class?
Cadenza
On your own (separate from your partner) write a short paragraph about
your peer-programming experience.
What worked well, what didn't?
How well was the work shared between you?
Was there anything particularly challenging about this assignment?
If so, what?
Hand in this write-up at the next lecture after the assignment is due.
Footnote: Several methods require you to
"print out every student..." Two points about this:
1. Since
there could be many students, pause after each 20 lines (or some
appropriate number) and ask the user whether or not to continue.
2. Use the following standard order for the data (keep it to one line
if possible):
Last name, first name, ID, GPA, date of
birth,
major, graduated or not
In addition, if the information printed spans more than one year,
place the appropriate year at the beginning of each line. 4/30/2004: The GPA for some students
has lots of places after the decimal point, such as 3.3700000002.
You don't have to do anything special to truncate or format these
number or otherwise make your printing of them look pretty. Of
course, if you want to round them off to two decimal places, that's
fine, too.