A03

Due Date: Thursday, January 29
File(s) to be submitted: KeepSmallInt.java
Sample Output: SampleOutput.html
Starter Files:


SUBMIT   /   Check

KeepSmallInt (Non-recursive Sorting)

Summary

Create a class named KeepSmallInt that uses an array to hold a given number of small integer values. Use the program TestKeepSmall to test your implementation.

Details

Your grading scheme for this course calculates your assignment grade by dropping the three smallest of your ten assignment scores. Naturally I will need to find the three smallest values among all your assignment grades. This week you will create a class that helps me do that.

I will actually do this with a spreadsheet, but in principle I could write a Java program to do it.

Your class is designed to keep track of a (fixed, finite) number of integer values. The class allows any integer values, altho' the testing program restricts itself to grades (integers in the range 0 to 100). The client can add as many values as they like to the KeepSmallInt object, but only the smallest values are kept. (The number of smallest values to keep is set by the constructor.)

For example, if the KeepSmallInt object is set to remember three values, and the client adds 10, 20, 30, 40, 50, 5, -4 and 100 to it, then the object remembers only the -4, 5 and 10.

Your class needs the following contructors and methods:

Hints

It'll be helpful if you make the array one space larger than it "needs" to be. For example, if it's remembering 2 grades, make the array size 3. That'll give you space to enter an extra value, and the value ending up in the last element of the array is the one that gets "bumped out". Just be careful to remember that the element in the "extra" position is (technically) not in the container!

You are not allowed to use a (full) sorting algorithm on your private array. Instead use the insert algorithm described in the course notes. Then even if the container is very large (remembering the 1000 smallest elements it's been presented with, for example), considering an element for insertion will still go (relatively) quickly.


SUBMIT   /   Check