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.

  1. 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?
  2. In total, how many students are there in year 1880?  Which one has the highest GPA?
  3. Having seen all the 1880 students, what can you type to get back to the first one (without creating a new BasicClassList object).
  4. 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?
  5. What does the   compareTo   method do? Try it out! (Hint: you'll need at least two pieces of student data to use this. . .)
  6. 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:

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.

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:

Coda

Discuss the following questions with you partner and answer them in a file called coda.txt.

  1. What are some reasons for wanting to minimize writing duplicated code?
  2. 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?
  3. 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.