Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- {
- private int apples;
- public boolean isEmpty(int apples)
- {
- if (apples == 0)
- return true;
- return false;
- }
- public boolean isFull(int apples)
- {
- if (apples == 125)
- return true;
- else
- return false;
- }
- public String print(int apples)
- {
- System.out.println("This bushel basket has" + this.apples + "apples in it.");
- return print;
- }
- //public int apples; /*Global Scope*/
- public int pick(int apples/*Local Scope*/)
- {
- /*Global Scope*/ // Local Scope
- this.apples += apples;
- if (this.apples > 125)
- {
- //Oops! We spilled.
- this.apples = 125;
- //Assuming set of real apples is [1,125]
- }
- //We return an integer, presumably the apple count
- return this.apples;
- }
- public int eat(int apples)
- {
- this.apples -= apples;
- if (this.apples < 0)
- {
- this.apples =0;
- }
- return eat;
- }
- public int spill(int apples)
- {
- this.apples = 0;
- return spill;
- }
- public String roomLeftInBasket(int apples)
- {
- return 125 - this.apples;
- }
- public void setApples(int a)
- {
- apples = a;
- }
- public int getApples()
- {
- return apples;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement