Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code these two parts for me, in Java!! (Part A): (Part B): Here's my code that you can use for reference, if you want:

Please code these two parts for me, in Java!!

(Part A):

image text in transcribed

(Part B):

image text in transcribed

Here's my code that you can use for reference, if you want:

image text in transcribedimage text in transcribedimage text in transcribed

Add the following two methods to the FancyArray class: - public int indexOf(E e): returns the index of the first occurrence of e in this FancyArray; if e does not occur in this FancyArray, returns 1. - public int lastIndexOf( Ee) : returns the index of the last occurrence of e in this FancyArray; if e does not occur in this FancyArray, returns 1. For example, if fa is a FancyArray representing [5,10,15,10,20], then: - fa.indexOf(10) should be 1 - fa.lastIndexOf(10) should be 3 - fa.indexOf(25) should be -1 - fa.lastIndexOf(25) should be 1 Note: If you wish, you can make the parameter type be Object instead of E. It doesn't really matter for this exercise. 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. - 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

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

List 5 IoT security risks from home smart device

Answered: 1 week ago

Question

=+ For what reasons can and do unions go on strike?

Answered: 1 week ago

Question

=+ Is secondary industrial action common and/or legal?

Answered: 1 week ago

Question

=+What sanctions are available to employers

Answered: 1 week ago