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

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0

    Java Help needed


    Apples in the Orchard

    Introduction
    Assume that a group of people have gone to a local apple orchard to pick some apples. Each person is given a bushel basket that they can fill up with apples. Each bushel basket holds 125 apples -- if you try to put more apples in the basket, they just roll off the top and fall to the ground. For this program you are going to write the BushelBasket class. The BushelBasket class is going to have objects that are very well encapsulated -- i.e., the data at the heart of each object, which is the number of apples currently in the basket, is always going to be accurate and cannot be corrupted.

    The main method below shows how the BushelBasket object gets used. You can create a basket that is empty, or it might already have some apples in it. The value number of apples that can be in a basket is between zero and 125, inclusive. If there is an attempt to create a basket with a negative number of apples, then set the basket count to zero. If they try to create a basket with more than 125 apples, set the count to 125.

    As people pick apples, the number of apples in their basket increases. If they eat apples from their basket, then the number of apples in their basket decreases. If they spill their basket, then count goes to zero.

    There are several boolean and int value returning methods in a BushelBasket object. The isEmpty and isFull methods let you know if the basket is empty or full (each of these methods returns a boolean value). You can also call getApples to get a current count of the number of apples currently in the basket, and roomLeftInBasket lets you know how many apples you still have to pick to fill the basket.

    Take the code below, copy it into jGRASP, and complete the BushelBasket class. When you run the main method below with your BushelBasket class, then you should get the output shown here:

    Output
    Rick...
    This bushel basket has 0 apples in it.
    This bushel basket has 33 apples in it.
    This bushel basket has 29 apples in it.
    This bushel basket has 0 apples in it.
    Newt...
    This bushel basket has 100 apples in it.
    false
    false
    100
    25
    Michele...
    true
    false
    false
    false
    false
    true
    Herman...
    This bushel basket has 0 apples in it.
    Jon...
    This bushel basket has 125 apples in it.
    Ron...
    This bushel basket has 20 apples in it.
    This bushel basket has 0 apples in it.
    This bushel basket has 125 apples in it.
    Gary...
    This bushel basket has 0 apples in it.
    Starting Code
    public class AppleOrchard
    {
    public static void main(String [] args)
    {
    System.out.println("Rick...");
    BushelBasket rick = new BushelBasket(0);
    rick.print();
    rick.pick(11);
    rick.pick(22);
    rick.print();
    rick.eat(4);
    rick.print();
    rick.spill();
    rick.print();

    System.out.println("Newt...");
    BushelBasket newt = new BushelBasket(100);
    newt.print();

    System.out.println( newt.isEmpty() );
    System.out.println( newt.isFull() );
    System.out.println( newt.getApples() );
    System.out.println( newt.roomLeftInBasket() );

    System.out.println("Michele...");
    BushelBasket michele = new BushelBasket(0);
    System.out.println( michele.isEmpty() );
    System.out.println( michele.isFull() );
    michele.pick(25);
    System.out.println( michele.isEmpty() );
    System.out.println( michele.isFull() );
    michele.pick(100);
    System.out.println( michele.isEmpty() );
    System.out.println( michele.isFull() );

    System.out.println("Herman...");
    BushelBasket herman = new BushelBasket(-5); // should default to 0
    herman.print();

    System.out.println("Jon...");
    BushelBasket jon = new BushelBasket(300); // should default to 125
    jon.print();

    System.out.println("Ron...");
    BushelBasket ron = new BushelBasket(20); // starts with 20
    ron.print();
    ron.eat(50); // can only eat down to zero apples
    ron.print(); // should see zero apples
    ron.eat(10); // back to 10
    ron.pick(1000); // basket can only hold 125 apples
    ron.print(); // should print 125

    System.out.println("Gary...");
    BushelBasket gary = new BushelBasket(); // should default to 0
    gary.print();
    }
    }

    class BushelBasket
    {
    // Write your code here.
    }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    25
    Rep Power
    0
    1. We dont do your homework. We only help you doing it yourself.
    2. learn to use the code-tag. It makes reading sourcecode much easier and increases your chance to get help
    3. whats the question? Again: "This is the assignment, do it for me" is not going to work.

IMN logo majestic logo threadwatch logo seochat tools logo