FHTW Berlin Medieninformatik

FHTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Winter Term 2008/09


Exercise 7: Fun with Calculators - Week 1

Finger exercises
  1. Dig out your Informatics 1 stuff. There was a calculator exercise, wasn't there? Have a look at how you solved the problem of reading in a digit followed by an operator followed by a digit, and how you figured out how to calculate the value when = was pressed.
  2. If you did not do Informatics 1 with me, or you didn't get much working last semester, I have a nice solution here: Main.java, ButtonHandler.java, Calculator.java and CalculatorGUI.java. Beware: do not expect to read and understand this in the first few minutes of the lab! Read it again at home, discuss it with others! How did it work?
  3. You might want to make sure that your infix-to-postfix and evaluate-postfix methods are in working order! If not, ask to use one from a friend. Re-use is good, if you give proper credit in your report.

Lab exercises

  1. Make a copy of your Calculator and get it loaded into Eclipse. Make sure that it works before you begin!
  2. Rework it to accept a long String of digits separated by operators. The bored may use multi-digit numbers and floating-point or scientific notation, if they please.
  3. Once you get a String input, add in calls to convert this expression to postfix and evaluate the postfix when = is pressed. Presto, your calculator now takes care of operator priorities, like magic! Just a little bit of mathematical thought, and you can introduce lots of new functionality!.

For the bored:

  1. Extend your integer calculator to include buttons for entering in the digits 'A' to 'F'. Make the calculator do its calculations and display in hexadecimal notation. Have a checkbox for switching between decimal and hexadecimal formats. Or make a whole collection of calculators: binary, octal, decimal, hexadecimal. Maybe make a CalculatorFactory that takes the base as a parameter to the constructor, figures out how to layout the buttons nicely, and calculates in the selected base mode?
Work in groups of two, and just submit one report, detailing who did what part of the work. Your reports are due by 23.55 next Wednesday.


Copyright 2008 Prof. Dr. Debora Weber-Wulff
All rights reserved.
Questions or comments: <weberwu@fhtw-berlin.de>
Copyright and Warranty