Swimming Pool class


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Creating Swimming pool class
  2.  
  3. public class SwimmingPool {
  4.  
  5. // constant
  6.  
  7. private final float CAPACITY_CUBIC_FOOT = 7.48f;
  8.  
  9. // instance variable
  10.  
  11. private float lengthOfPool;
  12. private float widthOfPool;
  13. private float shallwoDeptOfPool;
  14. private float deepDepthOfPool;
  15. private float volume;
  16. private float capacity;
  17.  
  18. // Constructor
  19.  
  20. public SwimmingPool ( float length,
  21. float shallowEndDept,
  22. float deepEndDepth)
  23.  
  24. {
  25. lengthOfPool = length;
  26. widthOfPool = width;
  27. shallowDeptOfPool = deepEndDept;
  28. }
  29.  
  30. // instance methods
  31.  
  32. public float volumeOfWater() {
  33.  
  34. volume=0.5f*(lengthOfPool*widthOfPool)*(shallowDeptOfPool + deepDepthOfPool);
  35. return volume;
  36. }
  37.  
  38. public float capacityOfPool() {
  39. capacity = volume *CAPACITY_CUBIC_FOOT;
  40. return capacity;
  41. }
  42.  
  43. public float timeToFillPool (float rateOfFlow) {
  44. return (capacity / rateOfFlow) / 60.0f;
  45. }
  46.  
  47. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.