2014-12-01 SuperArray

posted Dec 1, 2014, 7:36 AM by Samuel Konstantinovich   [ updated Dec 1, 2014, 9:30 AM ]

Change SuperArray

  • Take your SuperArray code and make a copy in folder 04OrderedSuperArray.
  • Change the data type from Object/Integer to String
  • You may have to change references from == to .equals (or compareTo)

Make a new class OrderedSuperArray

OrderedSuperArray acts like SuperArray but always maintains the array in sorted order, that is Strings that start with "a" come before words that start with "b" etc. Use the String compareTo to determine the location.

Notes:

  • OrderedSuperArray must extend SuperArray
  • The add(index,element) routine no longer makes sense - what should you do with it?
  • The add(element) routine used to add to the end of the SuperArray, change it so that it adds the new element in it's proper location.
  • When you get the basic class working, overload the set method. It should change the value of the element and then move it to its proper location.

DO NOT: use the built in Arrays.sort() command.

Extras:

  • If you are ambitious you can look to change SuperArrray to use generics (do a search for Java generics) - Generics are the Java feature that let us specify the type in the angle brackets. For example, when we use ArrayLists: ArrayList<String> or ArrayList<Integer>
ċ
SuperArray.java
(2k)
Samuel Konstantinovich,
Dec 1, 2014, 9:29 AM
Comments