Let's build a simple coffee shop simulation.
Your task is to implement the sellCoffee()
function in the CoffeeShop
class. This function should create a
new CoffeeCup
, set its attributes, and serve the coffee using the Kotlin apply()
scope function.
- The
CoffeeShop
class has to be defined using thesellCoffee()
method. - The
sellCoffee()
method should accept aclientName
andcoffeeType
. - In the
sellCoffee()
function create aCoffeeCup
instance and initialize its attributes (clientName
,coffeeType
,isServed
). - Use the
apply()
scope function to set the properties ofCoffeeCup
and call theserveCoffee
method. - Return the initialized
CoffeeCup
.
- The
CoffeeCup
class should represent a cup of coffee with attributes likeclientName
,coffeeType
, andisServed
. - The
CoffeeShop
class should have asellCoffee()
method, which creates aCoffeeCup
, sets its attributes, and serves it.