Instance Variables And Methods From The Parent

Objective determine which instance variables and methods from the parent class can be used in a derived class. Use calls to super when you can, for example, in the SortedIntList constructor and in the SortedIntList toString() method (Add a heading to the printed list which says and then call the IntList toString() method).
Think about this what is the most efficient way to maintain the sorted list? You could
add an element to the sorted list and resort the list each time (inefficient) or ..
Turn in the final source for ListTest and SortedIntList. Also turn in the output
leaving the data given for IntList and the following 3 sets of data for SortedIntList (Data
from SortedIntList objects should print out in ascending sequence.):
100, 50, 200, 25
1, 105, 63, 41, 250, 77, 6
A Sorted Integer List
File IntList. for an . Save it to your directory and study
it; notice that the only things you can do are create a list of a fixed size and add an element to a list. If the list is already full, a message will be printed. File
contains code for a class that creates an IntList, puts some values in it, and prints it. Save
this to your directory and compile and run it to see how it works.
Now write a class SortedIntList that extends IntList. SortedIntList should be just like
IntList except that its elements should always be in sorted order from smallest to largest.
This means that when an element is inserted into a SortedIntList it should be put into its
sorted place, not just at the end of the array. To do this youll need to do two things when
you add a new element:
Walk down the array until you find the place where the new element should go.
Since the list is already sorted you can just keep looking at elements until you find
one that is at least as big as the one to be inserted.
Move down every element that will go after the new element, that is, everything
from the one you stop on to the end. This creates a slot in which you can put the new element. Be careful about the order in which you move them or youll overwrite your data!
Now you can insert the new element in the location you originally stopped on.
All of this will go into your add method, which will override the add method for the
IntList class. (Be sure to also check to see if you need to expand the array, just as in the
.) What other methods, if any, do you need to override? To test your class, modify so that after it creates and prints the IntList, it creates and prints a SortedIntList containing the same elements (inserted in the same order). When the list is printed, they should come out in sorted order.

Don't use plagiarized sources. Get Your Custom Essay on
Instance Variables And Methods From The Parent
Just from $13/Page
Order Essay
Still stressed from student homework?
Get quality assistance from academic writers!
error: Content is protected !!
Open chat
Need assignment help? You can contact our live agent via WhatsApp using +1 718 717 2861

Feel free to ask questions, clarifications, or discounts available when placing an order.

Order your essay today and save 30% with the discount code LOVE