Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 L but the idea is that in
freeWeights one can assign a Barbell or a Dumbbell to any of its elements.
A 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 builtin
sorting.
A arg constructor that creates a gym with no equipment empty arrays Make sure to
instantiate new arrays of length 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 addEquipmentFreeWeight 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 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 addEquipmentWeightMachine 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 getFreeWeightString 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 getWeightMachineString 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started