Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class MyArray { // No other data fields necessary. private E[] data; public MyArray( int size) { this .data = (E[]) ( new Comparable[size]);

  • public class MyArrayextends Comparable> {

    // No other data fields necessary.

    private E[] data;

    public MyArray(int size) {

    this.data = (E[]) (new Comparable[size]);

    }

  • Add a data field to your MyArray class to keep track of the size of your array. The size should be updated whenever something is added to or removed from your MyArray object.
  • Add a method to return the current size of your MyArray object.
  • append(item): This method will take an item and add it to the end of your MyArray object. Remember that the "end" will not necessarily be the end of the internal array. This method will need to make sure that there is enough space to add the new item.
  • resize(): This should be a private method which will handle resizing your internal array. This method shall double the size of the internal array whenever this method is called.
  • contains(item): This method will search for a given item and return true or false depending on whether or not the item exists within the MyArray object.
  • delete(index): This method will remove the item at the given index. This method must shift the array so that the removed item does not leave a gap in the data. Be sure to validate that the index is within bounds and throw the appropriate exception if not.
  • delete(item): This method is an overload of the previous method. This version will remove the first occurrence of the given item from the MyArray object. This method must shift the array so that the removed item does not leave a gap in the data. This method should return true if the item was found and deleted, and return false if the item was not found.

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_2

Step: 3

blur-text-image_3

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

What aspects would it be impossible to capture?

Answered: 1 week ago

Question

Enhance your words with effective presentation aids

Answered: 1 week ago