Polymorphic Orderer
Geoffrey Challen // 2021.9.0
Create a public class named Orderer
that provides a single class 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
Fancy
restaurant withname
"MIGA" you should order "At MIGA I'll order something inexpensive" - If the restaurant is a
FastFood
restaurant withname
"Chipotle" you should order "At Chipotle I'll order something healthy" - If the restaurant is a
Vegan
restaurant, then they will have aString
property cuisine you can retrieve usinggetCuisine
. If their cuisine is "Thai" andname
is "Vegan Delight" you should order "At Vegan Delight I'll order delicious Thai food".
All Restaurant
s have a name that you can retrieve using getName
.
If the restaurant is null
or not one of the kinds described above, return null
.
Do not solve this problem using method overloading.
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 Java's object model.