Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code this in java! Thank You!! Write a class named FancyStringArray. An object of this class should be designed to store some Strings. Internally,

Please code this in java! Thank You!!

image text in transcribed

Write a class named FancyStringArray. An object of this class should be designed to store some Strings. Internally, these Strings should be stored in an array. capacity, then the FancyStringArray should have a capacity of 10. Separate from the notion of capacity, there is also a notion of size. The size of a FancyStringArray is the number of elements that it is currently storing. stored at indexes 0 through 2. When we add a fourth element, it should be placed at index 3. The class should have the following constructors: - public FancyStringArray() - public FancyStringArray(int capacity) The class should have the following methods: - public int size() - public void add(String element) - public String get(int index) // returns the element at the specified index - public String set(int index, String newElement) // replaces the old element at the specified index with the new element, and returns the old element - public boolean contains(String s) // determines whether this FancyStringArray contains s here: two FancyStringArrays can be considered equal even if they have different capacities. Throwing exceptions: - The second constructor should throw an IllegalArgumentException if the provided capacity is negative. - The add method should throw an IllegalStateException if the array is full. - The get and set methods 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 FancyStringArray class

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

Students also viewed these Databases questions

Question

Determine the amplitude and period of each function.

Answered: 1 week ago