












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
class
Coffee { void
prepareRecipe()
boilWater();brewCoffeeGrinds();pourInCup();addSugarAndMilk(); } public
void
boilWater()
} public
void
brewCoffeeGrinds()
} public
void
pourInCup()
} public
void
addSugarAndMilk()
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
class
Tea
void
prepareRecipe()
boilWater();steepTeaBag();pourInCup();addLemon(); } public
void
boilWater()
} public
void
steepTeaBag()
} public
void
pourInCup()
} public
void
addLemon()
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
primitiveOperation1();primitiveOperation2();
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
public
class
Coffee
extends
CaffeineBeverage
public
void
brew()
System.out.println("Dripping
Coffee through filter");
} public
void
addCondiments() { System.out.println("Adding
Sugar
and
Milk");
public
class
Tea
extends
CaffeineBeverage
public
void
brew()
System.out.println("Steeping
the
tea");
} public
void
addCondiments() {System.out.println("Adding
Lemon");
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
{
public void
brew() {... } public void
addCondiments() {... } public boolean customerWantsCondiments() {
String answer =
getUserInput();
if (answer.toLowerCase().startsWith("y")) {
return true; }^ else {
return false; } } private
String getUserInput() {... } }
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science
Leaf operation()
Composite add(Component)remove(Component)getChild(int)operation()
Client
U^ NIVERSITY OFUNIVERSITY OF
M^ ASSACHUSETTSMASSACHUSETTS
, A^ MHERST •, AMHERST
-^ Department of Computer ScienceDepartment of Computer Science