When a new player is registered, she/he
should be inserted into the Club class in alphabetical order of last name (and then first name
and then registration number if last names are the same). To do this make your Person and
Player class implement the Comparable interface.Write a Comparator class that compares players by batting average (number of runs scored
divided by no of times dismissed). If a player has never been dismissed list them at the
bottom of the averages in decreasing order of runs scored. Implement a new method
averages to the Club class that passes a Comparator to implement the above ordering.
Hence write a main program in a class Testing that will print information about each
player in the club where players are listed by decreasing order of batting average. This should
allow ordering to be dictated by the Comparator passed by the main program without
modifying the code in any of your classes.
This is my code for club class and I dont know how to do the registration bit and how to ipmplement comparable for average ....Please help me.
import java.util.*;
public class Club
{
private List<Player> list;
private List<WicketKeeper> list1;
private List<Bowler> list2;
private String clubname;
private static int regNum=0;
public Club(String name)
{
clubname=name;
list=new ArrayList<Player>();
list1=new ArrayList<WicketKeeper>();
list2=new ArrayList<Bowler>();
}
public void removePlayer(int IdPlayer)
{
list.remove(IdPlayer);
}
public Club(int Id)
{
regNum = Id;
}
public int getId()
{
return regNum;
}
public void add(Player p)
{
list.add(p);
regNum++;
}
public void add(WicketKeeper p)
{
list1.add(p);
}
public void add(Bowler p)
{
list2.add(p);
}