Java Reference
In-Depth Information
{
double volume;
double poolWaterCapacity;
volume = len * wid * dep;
poolWaterCapacity = volume * GALLONS_IN_A_CUBIC_FEET;
return poolWaterCapacity;
}
public static int poolFillTime( double len, double wid,
double dep, double fRate)
{
double poolWaterCapacity;
poolWaterCapacity = poolCapacity(len, wid, dep);
return ( int ) (poolWaterCapacity / fRate + 0.5);
}
public static void print( int fTime)
{
System.out.println("The time to fill the pool is "
+ "approximately: " + fTime / 60
+ " hour(s) and " + fTime % 60
+ " minute(s).");
7
}
}
Sample Run: (In this sample run, the user input is shaded.)
Enter the length, width, and the depth of the pool, (in feet): 30 15 10
Enter the rate of the water, (in gallons per minute): 100
The time to fill the pool is approximately: 5 hour(s) and 37 minute(s).
As you can see the program contains the method poolCapacity to find the amount of
water needed to fill the pool, the method poolFillTime to find the time to fill the pool,
and some other methods. Now to calculate the time to fill the pool, you must know the
amount of the water needed and the rate at which the water is released into the pool.
Because the results of the method poolCapacity are needed in the method
poolFillTime , the method poolFillTime cannot be tested alone. Does this mean that
we must write the method in a specific order? Not necessarily, especially, when different
people are working on different parts of the program. In situations such as these, we use
method stubs. A method stub is a method that is not fully coded. For a void method, a
method stub might consist of only a method header and a set of empty braces, {} , and for
a value-returning method it might contain only a return statement with a plausible return
value. For example, the method stub for the method poolCapacity can be:
public static double poolCapacity( double len, double wid, double dep)
{
return 1000.00;
}
Search WWH ::




Custom Search