0

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?

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • ^-- but without the reversing – dnault Aug 10 '20 at 18:49
  • 2
    You'll have better luck getting help here if you show us what you've tried so far. What's your best guess about how to implement the method? What error message are you getting after trying? – Garrett Disco Aug 10 '20 at 19:56
  • could you elaborate more on your `sorts the internal collection into its natural order` is it alphabetical?? or time of creation?? could you also give the `Name` object? – Akash Jain Aug 10 '20 at 21:17

0 Answers0