CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades | Students

Assignment #9

Display a sorted list of student scores

Due Date: Monday of Week 4
20 points

Console

This project uses a one-dimensional array that stores Student objects. The only complication is that the Student class implements the Comparable interface so that the Student objects in the array can be sorted (Do not create the Comparable interface. It already exists. You only need to implement it). The compareTo method has to provide for sorting by two fields. An enhanced for loop is used to display the sorted array.

Operation

  • This application accepts the last name, first name, and score for one or more students and stores the results in an array. Then, it prints the students and their scores in alphabetical order by last name.

Specifications

  • The program should implement a class named Student that stores the last name, first name, and score for each student. This class should implement the Comparable interface so the students can be sorted by name. If two students have the same last name, the first name should be used to determine the final sort order.
  • The program should use an array to store the Student objects. Then, it should sort the array prior to printing the student list.
  • Validate the input so the user can enter only a positive integer for the number of students, the last or first name can't be an empty string, and the score is an integer from 0 to 100.

Enhancements

  • Add the ability to sort the list by score. This turns out to be a surprisingly complicated enhancement. The easiest solution is probably to create a second student class (perhaps called StudentScore) that implements the Comparable interface to sort by score rather than by name.
Include in your program the following comments:
  • Name of program
  • Programmer's name
  • Current Date
  • Computer system and compiler you are using
  • Brief description of the program

Compile and run the Java program.

Take a screen capture by hitting simultaneously the keys Alt and Print Screen (Prt Sc) of the output results (console) and paste it in MS Paint. Save it as a gif file.

When you are ready, upload the java program and the gif file by clicking the link below:

Upload Assignment

I cannot grade if I don't get the files and receive your email.