Answered step by step
Verified Expert Solution
Link Copied!

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 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)
image text in transcribed

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

Can consultants replace outsourced activities? Why or why not?

Answered: 1 week ago