File integerlist | Computer Science homework help

 

File IntegerList.java contains a Java class representing a list of integers. The following public methods are
provided:
  IntegerList(int size)—creates a new list of size elements. Elements are initialized to 0.
  void randomize()—fills the list with random integers between 1 and 100, inclusive.

void print()—prints the array elements and indices
int search(int target)—looks for value target in the list using a linear (also called sequential) search
algorithm. Returns the index where it first appears if it is found, -1 otherwise.
void selectionSort()—sorts the lists into ascending order using the selection sort algorithm.
File IntegerListTest.java contains a Java program that provides menu-driven testing for the IntegerList class.
Copy both files to your directory, and compile and run IntegerListTest to see how it works. For example, create
a list, print it, and search for an element in the list. Does it return the correct index? Now look for an element
that is not in the list. Now sort the list and print it to verify that it is in sorted order.
Modify the code in these files as follows:
1. Add a method void replaceFirst(int oldVal, int newVal) to the IntegerList class that replaces the first
occurrence of oldVal in the list with newVal. If oldVal does not appear in the list, it should do nothing (but
it’s not an error). If oldVal appears multiple times, only the first occurrence should be replaced. Note that
you already have a method to find oldVal in the list; use it!
Add an option to the menu in IntegerListTest to test your new method.
2. Add a method void replaceAll(int oldVal, int newVal) to the IntegerList class that replaces all occurrences
of oldVal in the list with newVal. If oldVal does not appear in the list, it should do nothing (but it’s not an
error). Does it still make sense to use the search method like you did for replaceFirst, or should you do
your own searching here? Think about this.
Add an option to the menu in IntegerListTest to test your new method.
3. Add a method void sortDecreasing() to the IntegerList class that sorts the list into decreasing (instead of
increasing) order. Use the selection sort algorithm, but modify it to sort the other way. Be sure you change
the variable names so they make sense!
Add an option to the menu in IntegerListTest to test your new method.
4. Add a method int binarySearchD (int target) to the IntegerList class that uses a binary search to find the
target assuming the list is sorted in decreasing order. If the target is found, the method should return its
index; otherwise the method should return –1. Your algorithm will be a modification of the binary search
algorithm in listing
Add an option to the menu in IntegerListTest to test your new method. In testing, make sure your method
works on a list sorted in descending order then see what the method does if the list is not sorted
(it shouldn’t be able to find some things that are in the list).

 







Calculate Your Essay Price
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more

Enjoy 10% OFF today with the coupon code: best10