Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package lab 0 2 ; / * * * Capture a person who can drink soda. * A person can sip or gulp from a
package lab;
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 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
"thirsty" if they drank less than
"satisfied" if they drank at least
@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 lab;
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 lab;
Capture a Can of Soda.
A Can of Soda has a type, amount initially and is initially closed.
Once opened, you can sip take at most or gulp take at most from
the can. Obviously, at all times, the amount of soda in the can is between and
An opened can can not be closed.
public class SodaCan
Construct a new SodaCan of the specified type.
The new can has 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 cc of soda from this, provided this is open
@return the amount of soda actually removed
remove up to cc 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 thisisOpen"open":"closed";
return this.typeopenStringthis.amount;
Sodacan
Implement the class SodaCan using instance variables and methods to capture the following:
A SodaCan has a type ie Coke, Sprite, Root Beer it is either open or closed, it has an amount
of soda in it at least
For this question, assume that SodaCans start out closed with of soda in them.
A SodaCan be opened but can't be closed once opened
Once open, either sips remove or gulps remove can be taken from them.
Remember, amount must be at least ie if removing would make amount negative,
amount should become 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 openclosed 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 of soda. A thirsty person has had less than of
soda. A satisfied Person has had at least of soda.
Initially, a Person is very thirsty, since they have had no soda.
A person can sipFromSodaCan they can also gulpFromSodaCan
The string representation of a Person displays their name, their thirstStatus and the
amountDrunk.
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