Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Customised ArrayList An ArrayList is a dynamic, ordered collection of items. Such a structure is created from fixed size arrays and expand when the number

Customised ArrayList An ArrayList is a dynamic, ordered collection of items. Such a structure is created from fixed size arrays and expand when the number of items is reaching the maximum capacity. Typically, a dynamic array expands when there are more than 50% of the capacity used up but never reduces its size until it goes out of memory. In this assignment, you will ONLY use fixed size arrays to create your customised ArrayList (CAL). To simplify things, this dynamic array will contain String objects. You will allow the user to customize when to expand the array based on capacity (eg. More than 50% to 80% full), how many times you wish to expand, and whether to shrink the array when items are deleted from the array and triggers a shrinking of the array. 1 Moreover, the CAL can be made to store only non-duplicate strings by allowing the user to activate the method to store unique items. 1 Setting up (20%) Create a class called CustomisedArrayList. It should have an array field to represent the dynamic array, and fields such as the current size (refers to the number of items in the array), the maximum capacity, maximum capacity trigger point (eg. 80% of maximum capacity), capacity multiplier and a Boolean allowShrink to trigger shrinking if the array has fallen below 20% capacity. In addition, the CAL should have a constructor to initialize all the attributes. In your program you should determine the default values for such attributes if the user provides an invalid one. 2 Add Item (15%) Add a method public void addItem () to your class, which will allow the user to add an item to the dynamic array to any part of the array using an index. If the capacity hits or exceeds the maximum capacity trigger point, expand the capacity of the array by calling expandCapacity() below. If the index is zero or less than zero, the item will be inserted in the first position of the array. All the existing items must shift their positions by +1. If the index is greater or equal to the size of the number of items in the array, the item will simply be appended to the array. If the index is within the bounds, the item will be inserted at that position, shifting all the existing items from that position by +1. Inserting an item in the array will only increase the capacity of the array if the insert causes the size of the items to exceed 80% of the maximum capacity. 3 Expand Capacity (10%) Add a method public void expandCapacity () to your class, which will enlarge the array and copy all the array items (Use another method for this) over based on the trigger point. 2 4 Remove item at index (15%) Add a method public String removeAt (int index) that returns the item that is deleted in the array. If the number of items left fall below 20% of the maximum capacity, you can shrink the array to 50% of the original array size. If the item within the bounds of the size of the size of the number of items is removed, the item is returned and all items from the right will shift by -1 in position. If the item is out of bounds (index is less than zero or >= size), return null If the size is zero, return a null. 5 Get item (5%) Add a method public String getItem (int index) that returns the String object in that position. If any index given is invalid (below zero or equal to or more than the size), return null. 6 Store unique items (15%) Create a method to update the array to store only unique items. The method should return the number of duplicate items that are removed. If this method is called, the CAL should remove the duplicates in the underlying array and disallow any adding of elements that may result in duplicates in the data structure. The first occurrence of each unique item should be retained and all duplicates will be removed. 7 Testing the code (20%) Write a main method that does the following. 1. Creates a CustomisedArrayList object with initially 50 items, trigger point to be 80% full and triple the size of the array whenever the array becomes 100% full, with shrinking capabilities. 2. Read from a file of Strings (1000 strings) and populate the object created from part 1. 3. Let the user delete an item from the array and inform the user how many instances are removed.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

How would you respond to each of the girls?

Answered: 1 week ago