Write the definition of the class SwimmingPool, to implement the properties of a swimming pool. Your class should have the instance variables to atore the length(in feet), width (in feet), depth (in feet), the rate (in gallons per minute), at which the water is filling the pool, and the rate (in gallons per minute) at which the water is draining from the pool. And appropriate constructors to initialize the instance variables. Also, add member functions, to do the following: 1. Dtermine the amount of water needed to fill an empty pool or partially filled pool. 2. The time need to completely or partially fill the pool, or empty the pool; add water or drain for  a specific amount of time.   Here is my code that I have but not sure if it is correct. hank you:

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

Java User-Defined Classes

Write the definition of the class SwimmingPool, to implement the properties of a swimming pool. Your class should have the instance variables to atore the length(in feet), width (in feet), depth (in feet), the rate (in gallons per minute), at which the water is filling the pool, and the rate (in gallons per minute) at which the water is draining from the pool. And appropriate constructors to initialize the instance variables. Also, add member functions, to do the following:

1. Dtermine the amount of water needed to fill an empty pool or partially filled pool. 2. The time need to completely or partially fill the pool, or empty the pool; add water or drain for  a specific amount of time.

 

Here is my code that I have but not sure if it is correct. hank you:

public static void main(String[] args) {

double poolLength;
double poolWidth;
double poolDepth;
double gallonsOfWater;
double shallowEnd;
double deepEnd;
// System.out.println("Please enter the dimension of the swimming pool: ");

// poolLength = console.nextDouble();
// poolWidth = console.nextDouble();
// shallowEnd = console.nextDouble();
//deepEnd = console.nextDouble();


// poolDepth = shallowEnd + deepEnd ;

//poolDepth = poolDepth / 2;

// gallonsOfWater = poolLength * poolWidth * poolDepth * GALLONS_PER_CUBIC_FOOT;

// System.out.println("The number of gallons of water in your pool is: " + gallonsOfWater);

SwimmingPool pool = new SwimmingPool(30, 15, 10);
pool.setRateToFillPool(20);
pool.setRateToDrainPool(19.5);

// System.out.println("The amount of water needed is " + pool.CalculateAmountOfWaterNeeded(20, 10, 4.5));
System.out.println("The amount of water needed is " + pool.getAmountOfWaterNeeded());
System.out.println("The time needed to fill your pool is " + pool.TimeToFillPool());
System.out.println("The time needed to drain your pool is " + pool.TimeToDrainPool());
}
}

//The SwimmingPool Class

public class SwimmingPool {
private final double GALLONS_PER_CUBIC_FOOT = 7.48;
private double lengthOfPool;
private double widthOfPool;
private double depthOfPool;
private double volumeOfPool;
private double capacityOfPool;
private double TimeToFillPool;
private double TimeToEmptyPool;
private double ratePerMinuteToFillPool;
private double ratePerMinuteToDrainPool;
SwimmingPool(){

lengthOfPool = 0.0;
widthOfPool = 0.0;
depthOfPool = 0.0;
}
SwimmingPool(double length, double width, double depth)
{
lengthOfPool = length;
widthOfPool = width;
depthOfPool = depth;
}
public void setLength(double length){
lengthOfPool = length;
}

public void setWidth(double width){
widthOfPool = width;}

public void setDepth(double depth){
depthOfPool = depth;
}
public void setPooldimensions(double length, double width, double depth){

lengthOfPool = length;
widthOfPool = width;
depthOfPool = depth;
}

public void setRateToFillPool(double rateToFill){
ratePerMinuteToFillPool = rateToFill;

}
public void setRateToDrainPool(double rateToDrain){
ratePerMinuteToFillPool = rateToDrain;

}

public double getRateToFillPool(){
return ratePerMinuteToFillPool;

}
public double getRateToDrainPool(){
return ratePerMinuteToFillPool;

}
//public void setPooldimensions(double length, double width, double depth1, double depth2){

// lengthOfPool = length;
// widthOfPool = width;
//depthOfPool1 = depth1;
//depthOfPool2 = depth2;
//}
private double CalculateAmountOfWaterNeeded(double length, double width, double depth)
{
volumeOfPool = (length * width * depth) * GALLONS_PER_CUBIC_FOOT;
return volumeOfPool;
}
public double getAmountOfWaterNeeded()
{ return CalculateAmountOfWaterNeeded(lengthOfPool, widthOfPool, depthOfPool);
//return volumeOfPool;--using this variable will return nothing because I
//didnot declare a wor,ing variable as a placeholder
}
// public double CalculateCapacityOfWateInCubicFoot(double length, double width, double depth1, depth2)
// {
// double totalDepth = (depth1 + depth2) / 2;
// volumeOfPool = (length * width * totalDepth) * 7.48;
//return volumeOfPool;
//}
public double TimeToFillPool(){
TimeToFillPool = volumeOfPool / (ratePerMinuteToFillPool * 60);
//System.out.println("the time to fill the pool is " + TimeToFillPool + "hours ");
return TimeToFillPool;
}
public double TimeToDrainPool(){
//setRateToDrainPool(ratePerMinuteToDrainPool);
TimeToEmptyPool = volumeOfPool / (ratePerMinuteToFillPool * 60);
return TimeToEmptyPool ;
}
public void addWater(){

}
public void drainWater(){

}

}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,