CSE 201 - Lab 7 - Arrays


Note: This lab assumes that you have completed lab 1, and that you know how to login to your account, and how to open, edit, save your files, as well as compile and run your programs. If you have forgotten any of these techniques, refer back to the lab 1 handout. Be sure to follow the directions very carefully. If you have any problems or questions, be sure to ask your instructor as soon as possible. Points will be deducted if the submitted programs do not have the appropriate comments included.


Table of Contents


Objective

The objective for this lab is to write a Java program to practice the use of arrays. This lab will also reinforce program design and decomposition using Java class (static) methods. Monolithic solutions that do not exhibit a good design using appropriate class methods will not receive full credit.


Overview

You will complete a Java program from a given skeleton. The program will read information about students and their scores from a file, and output the name of each student with all his/her scores and the total score, plus the average score of the class, and the name and total score of the students with the highest and lowest total score.


Materials Provided

For this lab you will need the following three files:

You should complete the skeleton (i.e., complete all the methods) without modifying what is already there.

By the way, the skeleton will appear to have syntax errors in it when you open it. The reason is that all Java functions (methods returning a value) are supposed to contain a return statement to return their result. The functions in the skeleton, however, do not. Once you have added appropriate return statements to all the functions, the errors will be gone.

(You are allowed to make changes to the given skeleton, if you feel that that is necessary. But if the resulting design is considered by your instructor to be inferior to the one provided in the skeleton, your grade will reflect that. And, in any case, you MUST make use of appropriate class methods to structure your solution.)


Set up

Start Eclipse, create a new project, Lab7. Import into your Lab7 project the following files from K:\CSE201\Lab7 (see Lab 1 for instructions on how to import files in Eclipse):

After importing the files, you need to tell Eclipse where to find the FileIOHelper and Student classes. To do that, carefully follow these steps:

  1. Select the Lab7 project in the Package Explorer view;
  2. From the menu bar, select Project->Properties, the Properties window will appear;
  3. Select Java Build Path in the left panel of the Properties window, and the Libraries tab in the right panel;
  4. Click on the Add JARs... button, the JAR Selection dialog will appear;
  5. Expand the Lab7 folder and select the Lab7.jar file, and click OK;
  6. Click OK again, and you are done.

If, when using the Student and/or FileIOHelper classes in your lab, you get compiler errors saying that these classes are unknown, it probably indicates you made a mistake in this last setup step. In that case, you may want to come back and try the setup again.

Complete the Lab7 program according to the description below. If you don't remember how to create a project or a class in Eclipse, see Lab 1 for instructions.


Description

Here is a sample interaction between a user and the program you will write in the Lab7 class (user inputs are in bold):
    Enter input file name: info.txt

    Name                  Score1   Score2   Score3   Total
    --------------------------------------------------------
    Andy Borders          200      250      400      850   +
    John Borell           250      250      500      1000  +
    John Smith            120      220      330      670   -
    Brent Garland         210      230      340      780   =
    Robert Fennel         200      170      350      720   -
    Craig Fenner          230      220      480      930   +
    Bill Johnson          140      150      220      510   -
    --------------------------------------------------------
    The total number of students in this class is:  7
    The average total score of the class is:        780
    John Borell got the maximum total score of:     1000
    Bill Johnson got the minimum total score of:    510
    --------------------------------------------------------

The program performs the following actions:

  1. Ask the user to enter the name of a file containing information about student scores and input the file name (see Input file format for a description of the format of the input file);
  2. 
    
  3. Input the student information from the file and store it in an appropriate array of Student objects (see The Student Class for a description of this class, and The FileIOHelper Class for a description of how to use the FileIOHelper class to input the student records from a file);
  4. 
    
  5. Compute the total score for each student (and store those in another array) and the average total score;
  6. 
    
  7. Output in a well formatted table the name, individual scores, total score for each student, followed by a +, =, or - depending on whether the student total score is above, equal to, or below the average total score;
  8. 
    
  9. Output the number of students in the class, the average total score, and the maximum and minimum total score in the class (including the names of the students with the maximum and minimum score).
Note: To tabulate the output, you can count spaces or you can use tab characters. A tab character can be printed by using the '\t' escape sequence. For example, System.out.print("1\t2\t3") will output something like this:
1	2	3
where 1, 2, and 3 are separated by tabs.

Input File Format

The input file will contain information about student scores in the following format:
    <number of students>
    <student name>
    <score 1>
    <score 2>
    <score 3>
    <student name>
    <score 1>
    <score 2>
    <score 3>
    ...
where the first line <number of students> must contain the number of students in the input file, <student name> is a string representing a student name, and <score 1>, <score 2>, <score 3> are integers representing the three student scores. See info.txt for a sample input file in this format. Note that your solution must work with an input file following this format but with an arbitrary number of student records: make sure your code is not hard-coded to read in 7 students.

The FileIOHelper Class

The FileIOHelper class provides two class methods: To read an input file, getNumberOfStudents must be called first to get the number of students in the file. Then, getNextStudent must be called the appropriate number of times to input each student name and scores. If the input file is not in the correct format or the methods are not invoked in the correct sequence or the methods are invoked too many times, an error is generated and the program terminates.

The Student Class

A Student object has a name (String) and three scores (integers). The Student class provides the following (instance) methods to manipulate Student objects:


Running the Demo

To allow you to experiment with the program you are supposed to write, we have included a demo version of the lab in the Lab7.jar file. You can run the demo from within Eclipse by selecting the Lab7.jar file in the Package Explorer view, and then selecting from the menu bar Run->Run As->Java Application. The demo starts by displaying the message:

    *** This is the Lab7 Demo ***
so that you know you are running the demo.

You can/should create your own test input file, and can replace "info.txt" with the name of your file. Feel free to run and test this demo as much as you need to fully understand the expected behavior of your program.


Lab Submission

Make sure your program compiles and runs correctly before submitting. To submit, use the Submit tool available on the Widows desktop to submit the Lab7.java file from the Lab7 project (the location of the project in the file system will be z:\eclipse\workspace\Lab7). Make sure that you select lab7 from the list of Assignments. If you don't remember how to use the Submit tool, see Lab 1 for instructions.