Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

File IntList ava contains code for an integer list class. Save it to your directory and study it; notice that the only things you can

image text in transcribed
image text in transcribed
File IntList ava contains code for an integer list class. 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 List Test java 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 you'll 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 you'll 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 IntList add method.) What other methods, if any do you need to override? To test your class, modify ListTest.java 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 // IntList.java / An (unsorted) integer list class with a method to add an // integer to the list and a toString method that returns the contents // of the list with indices public class IntList protected int list; protected int numElements 0; /I Constructorcreates an integer list of a given size public IntList (int size) listnew int[size] / Adds an integer to the list If the list is full, // prints a message and does nothing public void add (int value) if (numElementslist System.out.println("Can't add, list is full else list [numElements] = value; numElements++

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

Navigating The Supply Chain Maze A Comprehensive Guide To Optimize Operations And Drive Success

Authors: Michael E Kirshteyn Ph D

1st Edition

B0CPQ2RBYC, 979-8870727585

More Books

Students also viewed these Databases questions

Question

Describe some of the ways that sexual development varies.

Answered: 1 week ago

Question

1. Identify three approaches to culture.

Answered: 1 week ago

Question

2. Define communication.

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago