Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BucketUse
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("enter bucket 2 capacity");
- double x = scan.nextDouble();
- Bucket b1 = new Bucket(600.00);
- Bucket b2 = new Bucket(x);
- if (b1.getCapacity()>b2.getCapacity())
- System.out.println("bucket number 1 has more capacity");
- else
- System.out.println("bucket number 2 has more capacity");
- }
- }
- sss
- import java.util.*;
- public class Bucket
- {
- private double capacity;
- private double currentAmount;
- private double getCapacity;
- public Bucket (double capacity)
- {
- this.capacity = capacity;
- this.currentAmount = 0;
- }
- public void print()
- {
- System.out.print (" (my capacity= " );
- System.out.println (this.capacity );
- System.out.print (" my current amount ");
- System.out.print ( this.currentAmount);
- System.out.println (" )" );
- }
- public void fill(double amountToFill)
- {
- if (this.capacity > (this.currentAmount + amountToFill) )
- this.currentAmount = this.currentAmount + amountToFill;
- else
- this.currentAmount = this.capacity;
- }
- public void empty(double amountToEmpty)
- {
- if (this.currentAmount < amountToEmpty)
- this.currentAmount = 0;
- else
- this.currentAmount = this.currentAmount - amountToEmpty;
- }
- public boolean isEmpty()
- {
- if (this.currentAmount == 0 )
- return true;
- else
- return false;
- }
- public void fillAll (){
- this.currentAmount = this.capacity;
- }
- public void emptyAll (){
- this.currentAmount = 0;
- }
- public boolean isFull()
- {
- if (this.currentAmount == this.capacity )
- return true;
- else
- return false;
- }
- public double getCapacity(){
- this.getCapacity=this.capacity-this.currentAmount;
- return this.getCapacity;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement