Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BucketUse
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner scan = new Scanner(System.in);
  8. System.out.println("enter bucket 2 capacity");
  9. double x = scan.nextDouble();
  10. Bucket b1 = new Bucket(600.00);
  11. Bucket b2 = new Bucket(x);
  12. if (b1.getCapacity()>b2.getCapacity())
  13. System.out.println("bucket number 1 has more capacity");
  14. else
  15. System.out.println("bucket number 2 has more capacity");
  16.  
  17. }
  18. }
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. sss
  26.  
  27.  
  28.  
  29.  
  30. import java.util.*;
  31.  
  32. public class Bucket
  33. {
  34.  
  35. private double capacity;
  36. private double currentAmount;
  37. private double getCapacity;
  38.  
  39.  
  40. public Bucket (double capacity)
  41. {
  42. this.capacity = capacity;
  43. this.currentAmount = 0;
  44. }
  45.  
  46.  
  47. public void print()
  48. {
  49. System.out.print (" (my capacity= " );
  50. System.out.println (this.capacity );
  51. System.out.print (" my current amount ");
  52. System.out.print ( this.currentAmount);
  53. System.out.println (" )" );
  54. }
  55.  
  56. public void fill(double amountToFill)
  57. {
  58. if (this.capacity > (this.currentAmount + amountToFill) )
  59. this.currentAmount = this.currentAmount + amountToFill;
  60. else
  61. this.currentAmount = this.capacity;
  62. }
  63.  
  64.  
  65.  
  66. public void empty(double amountToEmpty)
  67. {
  68. if (this.currentAmount < amountToEmpty)
  69. this.currentAmount = 0;
  70. else
  71. this.currentAmount = this.currentAmount - amountToEmpty;
  72. }
  73.  
  74.  
  75. public boolean isEmpty()
  76. {
  77. if (this.currentAmount == 0 )
  78. return true;
  79. else
  80. return false;
  81. }
  82. public void fillAll (){
  83. this.currentAmount = this.capacity;
  84. }
  85. public void emptyAll (){
  86. this.currentAmount = 0;
  87. }
  88. public boolean isFull()
  89. {
  90. if (this.currentAmount == this.capacity )
  91. return true;
  92. else
  93. return false;
  94. }
  95. public double getCapacity(){
  96. this.getCapacity=this.capacity-this.currentAmount;
  97. return this.getCapacity;
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement