Class SodaCan
java.lang.Object
SodaCan
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.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
SodaCan
Construct a new SodaCan of the specified type. The new can has 250 units in it, and is closed.- Parameters:
t
- the type of soda, for example "RootBeer", "Coke", "Cherry"
-
-
Method Details
-
open
public void open()open this SodaCan -
isOpen
public boolean isOpen()- Returns:
- whether this is open
-
sip
public int sip()remove up to 10cc of soda from this, provided this is open- Returns:
- the amount of soda actually removed
-
gulp
public int gulp()remove up to 50cc of soda from this, provided this is open- Returns:
- the amount of soda actually removed
-
getAmount
public int getAmount()- Returns:
- the amount of soda left in this
-
toString
-