SE 450 - Object Oriented Software Development

Fall 2001/2002

Homework #4

Design and implement an applet that acts as a calculator for decimal, octal and hexidecimal numbers which is very similiar to the Windows calculator. You design should make use of the Strategy and Factory patterns described in class. Not only will you need to implement the UI but also classes that represent the numbers entered. The requirements are:

  1. User should choose the mode by selecting 1 of 3 radio buttons.
  2. There should be 2 text fields that accept arguments.
  3. There should be a choice for the 2 operations: addition and subtraction.
  4. When the user presses the "ENTER" key in the second text field the result should be calculated and placed into a third text field. (Hint: this has to do with the KeyListener event in text fields. Info on this can be found in the Java Tutorial.)
  5. There should be a button that clears the calculator.
  6. Assume that the user will only type in correct numbers into the text fields depending on mode. You can handle this if you want. You do not have to handle negative numbers. For example, the user will not enter in any digit greater than 9 in deciaml, greater than 7 in octal or greater than F in hex.
  7. Your factory should throw an exception if the factory is asked to create a number format that is not either decimal, octal or hex. For example, in your code you write NumberFactory.create("Foo"). Your factory should throw an exception becuase "Foo" is not a supported number type.
  8. (2 extra credit points) Implement multiplication for all three number types.
An example of the applet can be found here.