Java programming editon 5. chapter 8 excersie 6. Write a definition of a class,
ID: 3547214 • Letter: J
Question
Java programming editon 5. chapter 8 excersie 6. Write a definition of a class, swimmingPool, to implement the properties of a swimming pool. Your class should have the instance variables to store length (in feet), width (in feet), depth (in feet), and rate (in gallons per min) at which the water is filling the pool, and the rate 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
public class swimmingpoool
{
float length;
float width;
float filling_rate;
float dropping_rate;
float depth;
float water_in_tank;
float capacity;
swimmingpoool(float l,float w, float d,float f_r,float d_r,float w_t,float c)
{
this.length=l;
this.width=w;
this.depth=d;
this.filling_rate=f_r;
this.dropping_rate=d_r;
this.water_in_tank=w_t;
this.capacity=c;
}
void time_to()
{
float need=this.capacity-this.water_in_tank;
float time = need/filling_rate;
System.out.print(time);
time=this.water_in_tank/this.dropping_rate;
System.out.print(time);
}
public static void main(String [] args)
{
swimmingpool sp=new swimmingpool(2.1,0.2,3.5,1.1,2.1,200.2,350.0);
sp.time_to();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.