Polymorphic Orderer
Create a method named order.
order should accept a single parameter, a Restaurant? to order from, and return a String, a comment on your
order.
Depending on which subclass of Restaurant it is, you should respond differently:
- If the restaurant is a
Fancyrestaurant—for instance, withname"MIGA"—you should order "At MIGA I'll order something inexpensive" - If the restaurant is a
FastFoodrestaurant, for instance, with withname"Chipotle"—you should order "At Chipotle I'll order something healthy" - If the restaurant is a
Veganrestaurant, then it will have aStringproperty cuisine you can retrieve usinggetCuisine. For example, if it its cuisine is "Thai" andnameis "Vegan Delight", you should order "At Vegan Delight I'll order delicious Thai food".
All Restaurants have a name that you can retrieve as the property name.
If the restaurant is null or not one of the kinds described above, return null.
Do not solve this problem using method overloading.
And do not hard-code the answers.
Your solution should work for any Fancy, FastFood, or Vegan instance.
Note that we are not implying that there are not fancy vegan restaurants or fancy fast food restaurants or vegan fast-food restaurants. If anything, the ability of real entities to resist strict classification is one of the limitations of Kotlin's object model.