#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Error: missing return statement .... please help


    I've been trying to figure this out for a few hours now and im just not getting it.

    this is the error message:

    ----jGRASP exec: javac -g PickingBerries.java

    PickingBerries.java:123: error: missing return statement
    }
    ^
    1 error

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

    Code:
    Here's the 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\n", amount);
    lisa.pick(1);
    int now = lisa.getBerries();
    System.out.printf("After picking one more: %d\n", lisa.getBerries());

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

    System.out.printf("At the moment, together they have %d berries\n",
    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
    {
    int bucket; //will keep track of how many berries in bucket

    Bucket() //sets bucket to 0
    {
    bucket = 0;
    }

    /**
    The pick method accepts number of berries put in in main and adds to bucket.
    @param berryNum The number of berries picked.
    */
    void pick(int berryNum)
    {
    bucket = bucket + berryNum;
    }

    void spillAll() //sets bucket to 0
    {
    bucket = 0;
    }

    /**
    This getBerries method returns the value in the bucket field
    @return The number of berries in the bucket
    */
    int getBerries()
    {
    return(bucket);
    }

    /**
    This report method returns the value in the bucket field
    @return The number of berries in the bucket
    */
    void report()
    {
    System.out.println("This bucket has " + bucket + " berries.");
    }

    /**
    This isEmpty method returns true or false if bucket is empty
    @param isEmpty sets bucket to false if bucket is not empty.
    */
    boolean isEmpty()
    {
    boolean isEmpty;
    if (bucket == 0)
    {
    isEmpty = true;

    }
    else
    {
    isEmpty = false;
    }
    }
    }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Fixed it!


    Originally Posted by marikmarik77
    I've been trying to figure this out for a few hours now and im just not getting it.

    this is the error message:

    ----jGRASP exec: javac -g PickingBerries.java

    PickingBerries.java:123: error: missing return statement
    }
    ^
    1 error

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

    Code:
    Here's the 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\n", amount);
    lisa.pick(1);
    int now = lisa.getBerries();
    System.out.printf("After picking one more: %d\n", lisa.getBerries());

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

    System.out.printf("At the moment, together they have %d berries\n",
    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
    {
    int bucket; //will keep track of how many berries in bucket

    Bucket() //sets bucket to 0
    {
    bucket = 0;
    }

    /**
    The pick method accepts number of berries put in in main and adds to bucket.
    @param berryNum The number of berries picked.
    */
    void pick(int berryNum)
    {
    bucket = bucket + berryNum;
    }

    void spillAll() //sets bucket to 0
    {
    bucket = 0;
    }

    /**
    This getBerries method returns the value in the bucket field
    @return The number of berries in the bucket
    */
    int getBerries()
    {
    return(bucket);
    }

    /**
    This report method returns the value in the bucket field
    @return The number of berries in the bucket
    */
    void report()
    {
    System.out.println("This bucket has " + bucket + " berries.");
    }

    /**
    This isEmpty method returns true or false if bucket is empty
    @param isEmpty sets bucket to false if bucket is not empty.
    */
    boolean isEmpty()
    {
    boolean isEmpty;
    if (bucket == 0)
    {
    isEmpty = true;

    }
    else
    {
    isEmpty = false;
    }
    }
    }

    boolean isEmpty()
    {
    boolean isEmpty;
    if (bucket == 0)
    {
    isEmpty = true;

    }
    else
    {
    isEmpty = false;
    }

    return isEmpty;
    }

IMN logo majestic logo threadwatch logo seochat tools logo