Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the definition of a class, swimmingPool, to implement the properties of a

ID: 3547747 • 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.

Explanation / Answer

assuming standard rate of 1 gallon = 0.00378541 cubic meter

/*

* 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.*/

public class SwimmingPool {


int length; // in meter

int width;// in meter

int depth; // in meter

int waterFillingRate; // gallons/min

int waterDrainingRate; // gallons/min

public SwimmingPool() {}

public SwimmingPool(int length, int width, int depth, int waterFillRate, int waterDrainRate) {

this.length=length;

this.width=width;

this.depth=depth;

this.waterFillingRate=waterFillRate;

this.waterDrainingRate=waterDrainRate;

}

// assuming standard rate of 1 gallon = 0.00378541 cubic meter

public static void main(String[] args) {

// create the pool

SwimmingPool pool = new SwimmingPool(100, 120, 140, 5000, 3000);

// get amount of water to fill empty tank

long volumeOfWater = fillEmptyTank(pool.length, pool.width, pool.depth);

timeToFillEmptyTank(volumeOfWater, pool.waterFillingRate);

timeToDrainFullTank(volumeOfWater,pool.waterDrainingRate );

}

private static void timeToDrainFullTank(long volumeOfWater,

int waterDrainingRate) {

System.out.println("Time to drain full tank in minute is " + volumeOfWater/(waterDrainingRate*0.00378541));

}

private static void timeToFillEmptyTank(long volumeOfWater,

int waterFillingRate) {

System.out.println("Time to full the empty tank in minute is " + volumeOfWater/(waterFillingRate*0.00378541));

}

private static long fillEmptyTank(int len, int wid, int depth) {

System.out.println("The amount of water required to fill the tank = volume of tank");

// total volume of water in pool

long volumeOfWater = len * wid * depth; // in cubic meter

System.out.println("total cubic meter of water : " + volumeOfWater);

return volumeOfWater;

}

}