Question
java programming 5th edition chapter 8 user defined classes and ADTs use with strings. 1. Write the definition of a class called SwimmingPool, to implement
java programming 5th edition chapter 8 user defined classes and ADTs use with strings.
1. Write the definition of a class called SwimmingPool, to implement the properties of a swimming pool.
instance variables:
length (in feet)
width (in feet)
depth (in feet)
fillRate (rate at which water fills pool in gallons per minute)
drainRate (rate at which water drains from pool in gallons per minute)
currentGallons (current number of gallons to fill the pool)
totalGallons (number of gallons to fill the pool)
Constructor methods:
default constructor
values constructor
Member methods:
separate 'set' methods for all instance variables, except totalGallons, which will always be calculated
separate 'get' methods for all instance variables
Determine number of gallons the pool will hold (hint: the total gallons a rectangular pool will hold is the pool's volume * 7.5)
The time needed to completely fill the pool (based on the current gallons)
The time needed to completely drain the pool (based on the current gallons)
Modify the gallons if water is added or drained for a specific number of minutes
Output the values of all instance variables
2. Create a client that will do each of the following:
Instantiate a pool1 object with the default constructor.
Instantiate a pool2 object with the values constructor, use length = 16, width = 32, depth = 4.5, fillRate = 4, drainRate = 8, and currentGallons = 12000.
Use the output method to print all attribute values for both pools.
Use the set methods to assign length = 20, width = 40, depth = 5.5, fillrate = 4.5, drainrate = 10, and currentGallons = 25000 to pool1's attributes.
Calculate the totalGallons for pool1 and pool2.
Use the output methods to print the attribute's values for both pools.
Use the member method to calculate the time it will take to completely fill pool1. Use get methods to output the current gallons and additional gallons needed to fill the pool, along with the fill time.
Use the member method to calculate the time it will take to completly drain pool2. Use the get method to output the number of gallons along with the drain time.
Modify the currentGallons in pool1 if water is added for 5 hours
Modify the currentGallons in pool2 if water is drained for 10 hours
Use the output methods to print the attribute's values for both pools
output:
Pool 1 - Swimming Pool Attributes
Length: 0.0 feet
Width: 0.0 feet
Depth: 0.0 feet
Fill rate: 0.0 gallons/minute
Drain rate: 0.0 gallons/minute
Current gallons: 0.0 gallons
Total capacity: 0.0 gallons
Pool 2 - Swimming Pool Attributes:
Length: 16.0 feet
Width: 32.0 feet
Depth: 4.5 feet
Fill rate:4.0 gallons/minute
Drain rate: 8.0 gallons/minute
Current gallons: 12000.0 gallons
Total capacity: 0.0 gallons
Pool 1 - Swimming Pool Attributes:
Length: 20.0 feet
Width: 40.0 feet
Depth: 5.5 feet
Fill rate: 4.5 gallons/minute
Drain rate: 10.0 gallons/minute
Current gallons: 25000.0 gallons
Total capacity: 33000.0 gallons
Pool 2 - Swimming Pool Attributes:
Length: 16.0feet
Width: 32.0 feet
Depth: 4.5 feet
Fill rate: 4.0 gallons/minute
Drain rate: 8.0 gallons/minutes
Current gallons: 12000.0 gallons
Total capacity: 17280.0 gallons
Fill time data for pool 1:
Current gallons: 25000.0
Gallons needed to fill pool: 8000.0
Fill time: 1777.8 minutes
Drain time data for pool 2:
Current gallons: 12000.0
Drain time: 1500.0 minutes
Do you want to add water to or drain water from the pool?
1 - Add water
2 - Drain water
1
How many minutes will water water be added to the pool? 300
Do you want to add water to or drain water from the pool?
1 - Add water
2 - Drain water
2
How many minutes will water be drained from the pool? 600
Pool 1 - Swimming Pool Attributes:
Length: 20.0 feet
Width: 40.0 feet
Depth: 5.5 feet
Fill rate: 4.5 gallons/minute
Drain rate: 10.0 gallons/minute
Current gallons: 26350.0 gallons
Total capacity: 33000.0 gallons
Pool 2 - Swimming Pool Attributes:
Length: 16.0 feet
Width: 32.0 feet
Depth: 4.5 feet
Fill rate: 4.0 gallons/minute
Drain rate: 8.0 gallons/minute
Current gallons: 7200.0 gallons
Total capacity: 17280.0 gallons
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