Lab: Inheritance and polymorphism

In this lab, you'll take a working "Magic 8-Ball" and give it multiple states - normal, empathetic, angry and sarcastic. Each state will be implemented as a different class, which inherit from the default behavior that I already wrote.

Create a new C# console application, and paste this starter code into Program.cs: Program.cs

Since this is a console application, you will only need to commit that code file with your modifications. The repo is here:

https://cssvn.utrgv.edu/svn_etomai/201810_3328/lab07_8ball/<username>

You make me SO ANGRY

Create a new class, AngryOracle that inherits from Oracle. Override the update method so that it always sets the answer to ARGHGHAGHHGH!!!. In Program.main, change the code to start with an AngryOracle, and run the program again. Now it should just be yelling at you all the time.

Next, change back to the default Oracle, but update it so that if the input is Shouting (see the helper method Oracle.inputType, it responds with "Please stop shouting.". If the user shouts again, then it should switch to AngryOracle. To make the switch, pay attention to the return value from Oracle.update and the helper method Program.getOracle.

Next, make AngryOracle more interesting. Have it become more angry if the uesr keeps SHOUTING, stay the same if the user makes STATEMENTs, and calm back down if the user asks QUESTIONs. When it calms down enough, it should revert back to the default Oracle.

More variety

Sarcastic Oracle

Create a SarcasticOracle, which inherits from Oracle. Update Oracle so that if the user makes a STATEMENT, it says "That's not a question." and switches to the sarcastic state, which implements the following behavior:

  • Respond to all QUESTIONs by repeating and mocking the question.
  • Respond to all STATEMENTs with insults.
  • Respond to SHOUTING by saying "Okay! Okay!" and going back to the default state.

Empathetic Oracle

Create an EmpatheticOracle, which inherits from Oracle. Update Oracle so that if the user asks three QUESTIONs in a row, is switches to the empathetic state, which implements the following behavior:

  • Append "Isn't that great?!" to all postive answers.
  • Append "I'm so sorry." to all negative answers.
  • Append "You're so great." to all non-committal answers.
  • Respond to STATEMENTs and SHOUTING the same way that the default state does.

(For EmpatheticOracle, you might want to rearrange things in Oracle so that you don't have to duplicate code. Feel free to create new methods and move things around.