Have to code a register class in java eclipse following these requirements have done most of the requirements i have this one left:
a) In your Register class add a sort method sortRegister(), that sorts the internal collection into its natural order, i.e. that prescribed by the compareTo method of its elements.
this is what i have so far:
package lib;
import java.util.ArrayList;
public class Register {
//Fields
private ArrayList<Name> list;
//Constructors
public Register() {
list = new ArrayList<>();
}
//Methods
public void addName(Name n) {
list.add(n);
}
public Name removeName(int pos) {
return list.remove(pos);
}
public Name getName(int pos) {
return list.get(pos);
}
public int registerSize() {
return list.size();
}
public void clearRegister() {
list.clear();
}
public boolean isRegisterEmpty() {
return list.isEmpty();
}
public String toString() {
return "Register:[ list=" + list + "]";
}
}
how should i code the method?