HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Winter Term 2010/11
Exercise 5: Fun with Calculators - Week 1
Finger exercises
You all know what a calculator is! Here's some code: calculator-full-solution. Have a look at how it solves the problem of reading in a digit
followed by an operator followed by a digit, and how
to calculate the value when = is pressed.
Is there anything impoutant missing in this calculator? Beware:
do not expect to read and understand this in the first few minutes of the
lab! Read it at home, discuss it with others, perhaps over the class forum so that we can join in and help! How does it work?
What are hexadecimal numbers?
Lab exercises
Implement the missing functionality for single digit numbers and only one operator discovered in the pre-lab.
Extend your integer calculator to include buttons for entering
in the hexadecimal digits. Make the calculator do its calculations and display
in hexadecimal notation.
Integrate a checkbox for switching between decimal
and hexadecimal formats. Do not show the hexadecimal digits (or grey them out) when you have the calculator in decimal mode.
What test cases do you need to test your calculator?
For the bored:
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, each of you submitting the same report, detailing who did what
part of the work. Your reports are due by 23.00 next week.