Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package lab 0 2 ; / * * * Capture a person who can drink soda. * A person can sip or gulp from a

package lab02;
/**
* Capture a person who can drink soda.
* A person can sip or gulp from a can of soda.
* The person knows how much soda they have consumed,
* and know how thirsty they are.
*/
public class Person {
/**
* Construct a new Person with the given name.
* So far they will have consumed 0 soda
* @param name the name given to this person
*/
/**
* Take a sip from s, modifying the amount this has consumed
* @param s the can of soda this will gulp from
*/
/**
* Take a gulp from s, modifying the amount this has consumed
* @param s the can of soda this will gulp from
*/
/**
* A person is
* "very thirsty" if they drank less than 175,
* "thirsty" if they drank less than 375,
* "satisfied" if they drank at least 375
* @return the thirst status of this
*/
/**
* @return a string representation of this
*/
public String toString(){
return "I am "+this.name+", and I am "+this.getThirstStatus();
}
}
package lab02;
/**
* The main method of this class plays out a scenario...
* Jack has two cans of soda, RootBeer and GingerAle,
* Jill also has two cans, Cherry and Grape.
* Jack opens his RootBeer first, and gives it to Jill.
* Jill completely drinks the RootBeer.
* Jack asks her if she is still thirsty, Jill responds.
* Now Jill opens her Cherry soda and drinks it until
* she is satisfied, then gives it to Jack.
* He takes a sip, but doesn't like it.
* Jill checks how much is left in her Cherry soda, but decides
* not to drink any more. Jack asks Jill if he can try her Grape soda.
* Jill gives it to Jack and he opens it.
* Jack drinks about half of it, then stops and tells Jill how he now feels.
* Finally, they check the amount available in all of the cans.
*/
public class Scenario {
}
package lab02;
/**
* Capture a Can of Soda.
* A Can of Soda has a type, amount (initially 250) and is initially closed.
* Once opened, you can sip (take at most 10) or gulp (take at most 50) from
* the can. Obviously, at all times, the amount of soda in the can is between 0 and 250.
* An opened can can not be closed.
*/
public class SodaCan {
/**
* Construct a new SodaCan of the specified type.
* The new can has 250 units in it, and is closed.
* @param t the type of soda, for example "RootBeer", "Coke", "Cherry"
*/
/**
* open this SodaCan
*/
/**
* @return whether this is open
*/
/**
* remove up to 10cc of soda from this, provided this is open
* @return the amount of soda actually removed
*/
/**
* remove up to 50cc of soda from this, provided this is open
* @return the amount of soda actually removed
*/
/**
* @return the amount of soda left in this
*/
/**
* @return a string representation of this
*/
public String toString(){
String openString =(this.isOpen)?"open":"closed";
return this.type+""+openString+""+this.amount;
}
}
Sodacan
Implement the class SodaCan using instance variables and methods to capture the following:
A SodaCan has a type (i.e. Coke, Sprite, Root Beer), it is either open or closed, it has an amount
of soda in it (at least 0).
For this question, assume that SodaCans start out closed with 250cc of soda in them.
A SodaCan be opened (but can't be closed once opened).
Once open, either sips (remove 10cc) or gulps (remove 50cc) can be taken from them.
Remember, amount must be at least 0(i.e. if removing 10cc would make amount negative,
amount should become 0). Both methods should return the amount of soda actually removed.
The string representation (from method toString) of a SodaCan displays its type, whether or
not it is open/closed, and its amount.
Once you are done implementing this class, write a main method which creates a few SodaCans and
then takes sips and gulps from them.
Derson
Implement the class Person using instance variables and methods to capture the following:
A Person has a name and a thirstStatus which is 'satisfied', 'thirsty' or 'very thirsty', and
amountDrunk which keeps track of how much soda they have drunk so far.
A very thirsty person has had less than 175cc of soda. A thirsty person has had less than 375cc of
soda. A satisfied Person has had at least 375cc of soda.
Initially, a Person is very thirsty, since they have had no soda.
A person can sipFrom(SodaCan), they can also gulpFrom(SodaCan).
The string representation of a Person displays their name, their thirstStatus and the
amountDrunk.
image text in transcribed

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions