Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Draw the major organic product of the reaction shown below

Answered: 1 week ago

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago

Question

6. The cost of the training creates a need to show that it works.

Answered: 1 week ago