beyondgrader.com Logo
DemoBrowseAboutTeamLogin

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—for instance, with name "MIGA"—you should order "At MIGA I'll order something inexpensive"
  • If the restaurant is a FastFood restaurant, for instance, with with name "Chipotle"—you should order "At Chipotle I'll order something healthy"
  • If the restaurant is a Vegan restaurant, then it will have a String property cuisine you can retrieve using getCuisine. For example, if it its cuisine is "Thai" and name is "Vegan Delight", you should order "At Vegan Delight I'll order delicious Thai food".

All Restaurants 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. 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 Java's object model.