CS 35
Program 5
due Tues 27 Feb. by midnight
Your task is to write in Java a solution to the
name problem that was Program 4. Make
name-rank-number records objects of
a class you define. To solve the problem, I want
you to use one or more ArrayLists of these objects.
To sort your ArrayLists, I want you to use the
built-in sort from the Java Collections library.
The sort I have in mind has signature:
sort(List list, Comparator super T> c) .
You may want to reread chapters 4 and 6 of Weiss as
well as read the java documentation on Arraylists,
Comparators, and sort.
Your solution should be well documented. Remember to
start small and work in small increments with enough
scaffolding that you know what is happening as you
progress.
Happy computing.
Hint: I found it useful to have the following class
//***********************************************************
// Rankdescend.java Author: cfk
// An implementation of Comparator to be used in the
// Collections sort function to achieve descending order
// by the numb field.
//
//***********************************************************
import java.util.*;
public class Rankdescend implements Comparator
{
public int compare(Namerec a, Namerec b)
{
if( a.getNumb() > b.getNumb() ) return -1;
if (a.getNumb() == b.getNumb()) return 0;
return 1;
}
}
where Namerec was a class I defined whose instances had a
private numb
field and a public getNumb() method. I used a Rankdescend
object as follows
Rankdescend cmpr = new Rankdescend();
Collections.sort(pnames, cmpr);
--->