Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this Java question. Please provide the output to FancyArray.java if possible. Add the following methods to the FancyArray class: - public

I need help with this Java question. Please provide the output to FancyArray.java if possible.

image text in transcribed

Add the following methods to the FancyArray class: - public void add(int index, E element): Inserts the specified element at the specified position in this FancyArray. Shifts the element currently at that position (if any) and any subsequent elements to the right. - public E remove(int index): Removes the element at the specified position in this FancyArray. Shifts any subsequent elements to the left to fill in the gap. Returns the element that was removed. Examples: - Suppose fa1 is a FancyArray representing [5, 10, 15, 20]. After we say fa1.add(2, 25), fa1 should represent [5, 10, 25, 15, 20]. - Suppose fa2 is a FancyArray representing [5, 10, 15, 20]. After we say fa2.remove(1), fa2 should represent [5, 15, 20]. Throwing exceptions: - The add(int index, E element) method should throw an IllegalStateException if the array is already full. Also, this method should throw an IndexOutOfBoundsException if the provided index is negative, or if it is greater than the size. Note that it is possible to add an element at index size, as long as the array isn't already full. - The remove(int index) method should throw an IndexOutOfBoundsException if the provided index is negative, or if it is greater than or equal to the size. Note: do not use ArrayList (or any other kind of List or Collection) in the FancyArray class. Additional Notes: Regarding your code's standard output, CodeLab will check for case errors but will ignore whitespace (tabs, spaces, newlines) altogether

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

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

=+ c. a company president deciding whether to open a new factory

Answered: 1 week ago