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
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.
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?
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
Make a copy of your Calculator and get it loaded into Eclipse. Make sure that it works before you begin!
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.
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:
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.