Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need 2 things done: 1. You see that your new IntListSorted can find the minimu

ID: 3710609 • Letter: I

Question

I need 2 things done:

1. You see that your new IntListSorted can find the minimum and maximum values in the list in a much simpler and faster way than the superclass can. Override these methods with this faster approach. Modify your IntListTest class to use an IntListSorted instance instead of an IntList and try it out.

2. Besides overriding superclass functionality, subclasses can add functionality not available to the superclass. Write a method getMedian that returns the middle element of an IntListSorted. (Note: When the list contains an even number of items, just return the last element in the first half of the list, i.e., the element right before the "center" of the list. For example, in the case of [0, 1, 3, 10], 1 should be returned.) Demonstrate your code by adding additional statements to IntListTest.

Here is IntListTest:

public class IntListTest {

   public static void main(String[] args) {
     
      IntList list = new IntList();
     
      list.add(5);
      list.add(4);
      list.add(3);
      System.out.println(list);
      System.out.println("Size: " + list.size());
      System.out.println("Min: " + list.getMinimum());
      System.out.println("Max: " + list.getMaximum());
   }
}

Here is IntListSorted:

public class IntListSorted extends IntList
{
/**
   * Adds a new item to this list, inserting it so that
   * the list remains sorted.
   */
@Override
public void add(int newItem)
{
    if (size() == 0 || get(size() - 1) <= newItem)
    {
      super.add(newItem);
    }
    else
    {
      int i = size();
      while (i > 0 && newItem < get(i - 1))
      {
        i -= 1;
      }
     
      // now i is 0, or newItem >= list[i - 1], so put the new
      // element at position i
      super.add(i, newItem);
    }
}

/**
   * Inserts a new item in this list, inserting it so that
   * the list remains sorted. (The given index is ignored.)
   */
@Override
public void insert(int index, int newItem)
{
    this.add(newItem);
}
}

Explanation / Answer

Hi Dear,

You have not posted IntList class, so i can not all methods inside this class.

I have implemented my all IntList then implemented your requirement.

Output:

[5, 4, 3]
Size: 3
Min: 3
Max: 5

Process finished with exit code 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote