Question: Write the FULL Java code for the following Gym class. It represents Gyms, which are described by the equipment they have. This is a concrete

Write the FULL Java code for the following Gym class.
It represents Gyms, which are described by the equipment they have. This is a concrete class. It
will have:
The following instance variables: freeWeights (FreeWeight[]), weightMachines
(WeightMachine[]).
Note that it's possible to have an array with a component type that is an
abstract class. We will explore this more in L15, but the idea is that in
freeWeights one can assign a Barbell or a Dumbbell to any of its elements.
A 2-arg constructor that receives the two variables (in the same order). It will assign the
received array to the instances and will also sort the array.
Don't write your own sorting implementation in this HW. Stick to Java's built-in
sorting.
A 0-arg constructor that creates a gym with no equipment (empty arrays). Make sure to
instantiate new arrays of length 0 instead of keeping a default copy.
A void browseGymEquipment() method. It will print the String representation of all
the equipment in the gym in order, each in its own line. The "free weight" equipment
will go before the weight machines
A void addEquipment(FreeWeight) method that adds a new FreeWeight (which
could be a Barbell or a Dumbbell) to freeWeights. This method should ensure that
the new array is in the natural ordering of the elements. Don't modify the old array.
The easiest way to implement this is in O(nlogn), and that is a valid solution.
We invite you to think if there are any implementations with lower runtime
complexity, and if so, implement them (but we recommend focusing on the
basic implementation - you can do this after being done with your submissions).
A void addEquipment(WeightMachine) method that adds a new WeightMachine
to weightMachines. This is an overload of the previous addEquipment method, and
like it, it should ensure the new array is sorted, and the same note regarding the
runtime complexity applies.
A FreeWeight getFreeWeight(String) method that returns a FreeWeight
(could be a Barbell or a Dumbbell) if the parameter matches any of the IDs of the
FreeWeight in the gym, and null otherwise.
A WeightMachine getWeightMachine(String) method that behaves the same as
the one above but for weight machines.
An int getEquipmentCount() method that returns the equipment count (sum of
the number of "free weights" and weight machines)
 Write the FULL Java code for the following Gym class. It

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!