Write the definition of a class, swimmingPool, to implement the properties of a
ID: 3548293 • Letter: W
Question
Write the definition of a class, swimmingPool, to implement the properties of a swimming pool. Your class should have the instance variables to store 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. Add appropriate constructors to initialize the instance variables. Also add member functions, to do the following: Determine the amount of water needed to fill an empty or partially filled pool; the time needed to completely or partially fill the pool, or empty the pool; add water or drain for a specific amount of time.
***Need to define methods in the SwimmingPool class as instance methods, not static methods.***
Explanation / Answer
Hi,
Please find the code below. I hope you have formulas to calculate.
public class SwimmingPool {
float length;
float width;
float depth;
float fillRate;
float drainRate;
public SwimmingPool() {
// TODO Auto-generated constructor stub
}
public SwimmingPool(float length, float width, float depth, float fillRate,
float drainRate) {
this.length = length;
this.width = width;
this.fillRate = fillRate;
this.drainRate = drainRate;
}
public float getLength() {
return length;
}
public void setLength(float length) {
this.length = length;
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
this.width = width;
}
public float getDepth() {
return depth;
}
public void setDepth(float depth) {
this.depth = depth;
}
public float getFillRate() {
return fillRate;
}
public void setFillRate(float rate) {
this.fillRate = rate;
}
public float getDrainRate() {
return drainRate;
}
public void setDrainRate(float drainRate) {
this.drainRate = drainRate;
}
void calculateAmtOfWaterToFillPool() {
}
void calculateTimeToFillEmptyPool() {
}
void addWaterForSpecificTime(float time) {
}
void drainWaterForSpecificTime(float time) {
}
public static void main(String[] args) {
SwimmingPool pool = new SwimmingPool();
pool.setLength(20);
pool.setWidth(20);
pool.setDepth(6);
pool.setFillRate(100);
pool.setDrainRate(60);
pool.calculateAmtOfWaterToFillPool();
pool.calculateTimeToFillEmptyPool();
pool.addWaterForSpecificTime(1);
pool.drainWaterForSpecificTime(0.5f);
SwimmingPool swimpool = new SwimmingPool(10, 10, 7, 90, 50);
}
}
Hope it helps.
Thanks,
Sri
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.