Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MyArray Class This closs creates an array that can pet larger if necessary. The MyAray coject will contain a lava array to hold its elerments,

image text in transcribed
image text in transcribed
MyArray Class This closs creates an array that can pet larger if necessary. The MyAray coject will contain a lava array to hold its elerments, but the client/demo code cannot use subseriots since a Myafray object is not actually on array. Insteed the class will have mothods to add, modify, and access the elements stored in a Myarray object Each elemant stored in a MyAcray object has a position. The first elemert is at position 0 . Your dibis should have the following fields - myAirayi a gerniric array - numelements. ari int which specifies how many items hove been added to the MyArray object - gefCap an int initialzed to 10, which is the defoult size of a MyArray - CrigCap: an int which specifies the original size of the MyArroy Your class should have the following methods: - defoult constructor: Create on aray of size 10 , initialize orioCap to 10 and numElements to 9. - constructor with one int parameter. Create an array of the size given by the parameter, initialize origCap to the size of the array, and initialize numelements to 0 . - int size: Has no parrin; returns numelements. - vold addT item). append item to MyArray so that it is in the location right after what was the last element Cal expard if there is no rocm for another Item, then add the item - void odd(int loc, T item): add item to MyAray in location loc. ltems from focation loc to the end of the MyArray are shifted up to male room for item For exarple, if the MyAray contains "yea" "no" "red" "green", add(2, "blue") will return "year "no" "blue" "red" "yreen". add can be used to add in any evisting MyArry locotion or to the end of the MyArray. There cannot be any null items within the array, so if the array contains three elements you con add on element in loc three (the fourth element) bot you cen't add in ary loc higher than that. Throw IndewOutOfedinds Exception if loc is inuolid. Crall expand if there is no room for another item, then add the item. - void expand0: eypand is a private method, called by add to allocate a now inrger array. The expand method creates a new orray, copies the aray values into the new arrav, and saves this new aray in the myArray fleld the size of the new orray is the size of the existing arrey plus onigCap - Tremove(ent loc) remove the element in position loc and retum the element that was removed. Loter items are moved down to fill in position loc, and the "areen" null and retum 'blue"; Degernent numblements. Trrow IndexOutDriboundexception if the tubscript is invalid. - Tremove(T value) remove the first ocarrence of volue and return the If value is not in the aray it thews Nosuchilementexcegtion Loter iteris are moved down to fili in position loc, and nul is put in the last position, Subtract che from rurriementr for example, if the orray containg "yen" "na" "hise" "read" "grese", remove('blue") will change the oray to "Yen" "no " "rea " gareen" mali and retum 'blue" - I getcint): The porm is a subscript; get relurns the orray element at that woscipt. For exomple, get(7) will return the oth alernent in the artay throws Indesoutofisounds Exception if the evbscript is inyalid, Use numfilernente as the upoer bound, not the size of the array. - void set(int loc. I lem):- wet stores itern in the arrey at location loc. For example, set(7, 44) will store 44 as the ath element in the aray. If foc does not contain an aray element, throw ArraylndexDutOfBounds Exception. - Int indexOr(T item): search the array for item and return the subsoript whote item is focint in the array. If lem is not in the array notum -I If item is in the aray more than once, return the subsoript of the first occunence. - String tostringO return a String which contains the array elements separated by newlines

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

Discuss the various types of policies ?

Answered: 1 week ago

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

5. How would you describe your typical day at work?

Answered: 1 week ago

Question

7. What qualities do you see as necessary for your line of work?

Answered: 1 week ago