Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. image text in transcribedimage text in transcribed

  1. Then create and name the Class "OrderedArrayList" and make sure it extends UnorderedArrayList.
    1. You will want the same constructors as UnorderedArrayList (only these are for OrderedArrayList).
    2. Place the method to sort the array in this Class.
    3. 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.
      1. So when you swap elements in the array and need a temporary variable to store a value then that value will be of typeDataElement!
  2. 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.
    1. 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.
      1. Change all of the calls using the UnorderedArrayList array name to the OrderedArrayList array name.
      2. There should be NO instantiated arrays of UnorderedArrayList in the Driver.
  3. Using this same array, call all of the methods from the original Example3_1 program.
  4. 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions