Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help me finish this Java program code! Please!! This is what my teacher wants an

ID: 3641069 • Letter: H

Question

Help me finish this Java program code! Please!! This is what my teacher wants and I am stumped...please help.


The Bucket Class

This program keeps track of a bunch of people picking blackberries in the woods. The main method is already written in the PickingBerries class -- you need to create the class Bucket. A Bucket object keeps tracks of the number of blackberries that a person has picked and placed in their bucket. When a Bucket is created it has no berries in it. Then the number of berries in the bucket increases as the person picks berries. If the person picks ten berries, then the number of berries in the bucket goes up by ten.

There are two methods that let you know how many berries are currently in a bucket. The method report prints the status of the bucket to the console with System.out.println or System.out.printf (whichever print method you prefer). The message has the general format

This bucket has 15 berries.

You can also ask a bucket how many berries it currently contains with a call to getBerries. The getBerries method returns the number of berries currently in the bucket. Note that most of the methods in the Bucket class have a void return type, whereas the getBerries method is going to have an int return type, and the isEmpty method returns a boolean. The isEmpty method simply returns true if the number of berries in a bucket is currently zero, and returns false if there are some berries in the bucket.

Copy the code shown below into a file named PickingBerries.java, then complete the Bucket class by writing the following methods:

pick
spillAll
getBerries
report
isEmpty
Your program should give exactly the Expected Output shown below when run with the main method given in the PickingBerries class. Do not change the code in the main method in any way.

Expected Output

Out in the forest, some friends were picking blackberries...
Alan...
This bucket has 0 berries
This bucket has 12 berries
This bucket has 32 berries
This bucket has 0 berries
Lisa...
This bucket has 150 berries
Right now: 150
After picking one more: 151
Ian...
This bucket has 5 berries
At the moment, together they have 156 berries
Sallie has not picked any berries yet.
Sallie has picked some berries.
Run Your Program with this PickingBerries Code

public class PickingBerries
{
public static void main(String [] args)
{
System.out.println("Out in the forest, some friends were picking blackberries...");

Bucket alan = new Bucket(); // Alan has an empty bucket
Bucket lisa = new Bucket(); // Lisa has an empty bucket
Bucket ian = new Bucket();

System.out.println("Alan...");

alan.report(); // Prints to console: "This bucket has 0 berries."
alan.pick(10); // 10 in bucket now
alan.pick(2); // now up to 12
alan.report(); // Prints to console: "This bucket has 12 berries."

alan.pick(20); // now up to 32
alan.report();

alan.spillAll(); // all the berries spilled out of the bucket
alan.report(); // should report zero berries in the bucket here

System.out.println("Lisa...");
lisa.pick(100);
lisa.pick(50); // up to 150
lisa.report();

int amount = lisa.getBerries(); // the value 150 is returned and placed in amount
System.out.printf("Right now: %d ", amount);
lisa.pick(1);
int now = lisa.getBerries();
System.out.printf("After picking one more: %d ", lisa.getBerries());

System.out.println("Ian...");
ian.pick(5);
ian.report();

System.out.printf("At the moment, together they have %d berries ",
alan.getBerries() + lisa.getBerries() + ian.getBerries() );

Bucket sallie = new Bucket();

if (sallie.isEmpty())
System.out.println("Sallie has not picked any berries yet.");
else
System.out.println("Sallie has picked some berries.");

sallie.pick(10);
sallie.pick(33);

if (sallie.isEmpty())
System.out.println("Sallie has not picked any berries yet.");
else
System.out.println("Sallie has picked some berries.");
}
}

class Bucket
{
// Write your code here

Explanation / Answer


public class PickingBerries {
    
    public static void main(String[] args) {
        System.out.println("Out in the forest, some friends were picking blackberries...");

        Bucket alan = new Bucket(); // Alan has an empty bucket
        Bucket lisa = new Bucket(); // Lisa has an empty bucket
        Bucket ian = new Bucket();

        System.out.println("Alan...");

        alan.report(); // Prints to console: "This bucket has 0 berries."
        alan.pick(10); // 10 in bucket now
        alan.pick(2); // now up to 12
        alan.report(); // Prints to console: "This bucket has 12 berries."

        alan.pick(20); // now up to 32
        alan.report();

        alan.spillAll(); // all the berries spilled out of the bucket
        alan.report(); // should report zero berries in the bucket here

        System.out.println("Lisa...");
        lisa.pick(100);
        lisa.pick(50); // up to 150
        lisa.report();

        int amount = lisa.getBerries(); // the value 150 is returned and placed in amount
        System.out.printf("Right now: %d ", amount);
        lisa.pick(1);
        int now = lisa.getBerries();
        System.out.printf("After picking one more: %d ", lisa.getBerries());

        System.out.println("Ian...");
        ian.pick(5);
        ian.report();

        System.out.printf("At the moment, together they have %d berries ",
                alan.getBerries() + lisa.getBerries() + ian.getBerries());

        Bucket sallie = new Bucket();

        if (sallie.isEmpty()) {
            System.out.println("Sallie has not picked any berries yet.");
        } else {
            System.out.println("Sallie has picked some berries.");
        }

        sallie.pick(10);
        sallie.pick(33);

        if (sallie.isEmpty()) {
            System.out.println("Sallie has not picked any berries yet.");
        } else {
            System.out.println("Sallie has picked some berries.");
        }
    }
}

class Bucket {
     private int total;
     private String name;
     
     boolean isEmpty() {
         if(this.total==0) return true;         
         return false;
     }
     public void report() {
         System.out.println("The bucket has "+this.total+" berries");
     }
     public void pick(int count) {
         this.total = this.total+count;
     }
     int getBerries() {
         return this.total;
     }
     public void spillAll() {
         this.total=0;
     }
}
public class PickingBerries {
    
    public static void main(String[] args) {
        System.out.println("Out in the forest, some friends were picking blackberries...");

        Bucket alan = new Bucket(); // Alan has an empty bucket
        Bucket lisa = new Bucket(); // Lisa has an empty bucket
        Bucket ian = new Bucket();

        System.out.println("Alan...");

        alan.report(); // Prints to console: "This bucket has 0 berries."
        alan.pick(10); // 10 in bucket now
        alan.pick(2); // now up to 12
        alan.report(); // Prints to console: "This bucket has 12 berries."

        alan.pick(20); // now up to 32
        alan.report();

        alan.spillAll(); // all the berries spilled out of the bucket
        alan.report(); // should report zero berries in the bucket here

        System.out.println("Lisa...");
        lisa.pick(100);
        lisa.pick(50); // up to 150
        lisa.report();

        int amount = lisa.getBerries(); // the value 150 is returned and placed in amount
        System.out.printf("Right now: %d ", amount);
        lisa.pick(1);
        int now = lisa.getBerries();
        System.out.printf("After picking one more: %d ", lisa.getBerries());

        System.out.println("Ian...");
        ian.pick(5);
        ian.report();

        System.out.printf("At the moment, together they have %d berries ",
                alan.getBerries() + lisa.getBerries() + ian.getBerries());

        Bucket sallie = new Bucket();

        if (sallie.isEmpty()) {
            System.out.println("Sallie has not picked any berries yet.");
        } else {
            System.out.println("Sallie has picked some berries.");
        }

        sallie.pick(10);
        sallie.pick(33);

        if (sallie.isEmpty()) {
            System.out.println("Sallie has not picked any berries yet.");
        } else {
            System.out.println("Sallie has picked some berries.");
        }
    }
}

class Bucket {
     private int total;
     private String name;
     
     boolean isEmpty() {
         if(this.total==0) return true;         
         return false;
     }
     public void report() {
         System.out.println("The bucket has "+this.total+" berries");
     }
     public void pick(int count) {
         this.total = this.total+count;
     }
     int getBerries() {
         return this.total;
     }
     public void spillAll() {
         this.total=0;
     }
}