Question
Lab Goal: This lab was designed to teach you more about designing and writing classes. Use the same runner code below and associated comments to
Lab Goal: This lab was designed to teach you more about designing and writing classes. Use the same runner code below and associated comments to create a CookieJar class.
Lab Description : Write a CookieJar class that will is set to a capacity and tracks how much stuff the CookieJar is storing.
Sample Runner Code:
public class CookieJarRunner
{
public static void main( String[] args )
{
CookieJar c = new CookieJar( 3000 ); //sets capacity to 3000
System.out.println( c.isFull( ) ); //cookiejar is not full
c.addStuff( 500 ); //add 500 items
System.out.println( c.isFull( ) ); //cookiejar is not full
System.out.println( c.addStuff( 2000 ) ); //add 2000 items and return -500
//-500 indicates 500 items can be added
System.out.println( c.spaceLeft( ) ); //space left is 500
System.out.println( c.isFull( ) ); //cookiejar is not full
System.out.println( c.addStuff( 2000 ) ); //attempt to add 2000
//adds 500 and returns 1500
//1500 was amount left
//that could not be added
System.out.println( c.spaceLeft( ) ); //no space left ? returns 0
System.out.println( c.isFull( ) ); //returns true
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started