Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2) Java code Only. Create a class called ResizableArray. The only attribute it has is an array of Objects, which by default is initialized at

image text in transcribed

2)

image text in transcribed

Java code Only.

Create a class called ResizableArray. The only attribute it has is an array of Objects, which by default is initialized at size 10. It has a constructor accepting an int as parameter, which will initialize it at the size of the parameter. Give the class a method add(Object o). This will add the object to the first slot available (so keep track of the count of objects added.) If the array is filled to capacity, increase its size by creating a new array double the size, copying all objects to it, then assigning the new array to the instance variable. It might be wise to create a separate private method for doing this. Note: null is considered a valid 'object' to be added here. Create a method get(int index), which will return the object at index index or throw a suitable exception if the index is out of range. Create a method get(Object o), which will return the first object which is the same as the one provided as parameter, or null if that object cannot be found. Create a method remove(int index), which will delete the object at index index, then move all other objects so the array does not contain an invalid empty slot. Create a method remove(Object o), which will delete the first object which is the same as the one provided as parameter, then move all other objects as before. It is possible to think of several other useful methods, such as clear(), size() and addAll(ResizableArray), but this will do for now. You created an array which does not have the problem of a fixed size. A problem with the class is that it is not type-safe. Change it so it uses generics. It will have two constructors, ResizableArray and ResizableArray (int initialSize). The add method now only accepts T as parameter, the get methods will now return E instead of Object

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

More Books

Students also viewed these Databases questions

Question

Explain walter's model of dividend policy.

Answered: 1 week ago