Question: In java, redo the following program by creating and adding a Class called OrderedArrayList . This class will include a method to sort an array.
In java,
redo the following program by creating and adding a Class called OrderedArrayList. This class will include a method to sort an array. The datatype of the values within the array will be of type DataElement. 

- Then create and name the Class "OrderedArrayList" and make sure it extends UnorderedArrayList.
- You will want the same constructors as UnorderedArrayList (only these are for OrderedArrayList).
- Place the method to sort the array in this Class.
- Remember - the datatype here is DataElement!! This means that this class will work for both integers AND strings.DO NOT add any other methods to this Class. It should only contain the sort method.
- So when you swap elements in the array and need a temporary variable to store a value then that value will be of typeDataElement!
- In your Driver, instantiate an array of type OrderedArrayList. In your Driver, with the array you instantiated in step 2, use dot notation to call the sorting method.Then, print out the array to verify that it is sorted.
- Remove the instantiation of UnorderedArrayList array. You will only use the instantiated object of OrderedArrayList array.BecauseOrderedArrayList extends UnorderedArrayList, you also get to use all of the methods within UnorderedArrayList. You don't need to copy any into OrderedArrayList. Because UnorderedArrayList extends ArrayListClass, you also get to use all of the methods within ArrayListClass.To access any method - no matter which of the three classes the method belongs to, just use the same dot notation as shown in Example3_1.
- Change all of the calls using the UnorderedArrayList array name to the OrderedArrayList array name.
- There should be NO instantiated arrays of UnorderedArrayList in the Driver.
- Remove the instantiation of UnorderedArrayList array. You will only use the instantiated object of OrderedArrayList array.BecauseOrderedArrayList extends UnorderedArrayList, you also get to use all of the methods within UnorderedArrayList. You don't need to copy any into OrderedArrayList. Because UnorderedArrayList extends ArrayListClass, you also get to use all of the methods within ArrayListClass.To access any method - no matter which of the three classes the method belongs to, just use the same dot notation as shown in Example3_1.
- Using this same array, call all of the methods from the original Example3_1 program.
- You should find that everything works the same.
import java.io.*. import java.util.* public class Example3_1 static BufferedReader keyboardnew BufferedReader(new InputStreamReader(System.in)); public static void main(String args) throws IOException UnorderedArrayList intList = new UnorderedArrayList(50) /Line 1 UnorderedArrayList temp- new UnorderedArrayList) //Line 2 IntElement num new IntElement() //Line 3 int counter //Line 4 /Line 5 int position String Tokenizer tokenizer System.out.println(" Line 7: Processing the" System.out.print"Line 8: Enter 8 integers on the System.out. flush0 tokenizer new /Line 6 + "integer list") /Line 7 + "same line:" //Line 8 /Line 9 StringTokenizer(keyboard.readLine0) /Line 10 for(counter = 0; counter
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
