HTW Berlin
Fachbereich 4
Internationaler Bachelor Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Summer Term 2023
Exercise
9: Fun with Calculators 3
Finger
exercises
We are now going
to make a calculator for a different data type that just
integers. Of course, the bored are welcome to implement any
fascinating new data types they can think up for using a calculator
with! Choose one of the following data types:
Either polish
your extended JulianDate class or see if one of the
bored has made something useful. Make sure that you can read and
write dates in a specific format. Add methods such as public
void addDays (int days); if necessary. You will be
producing a date calculator. Decide how you are
going to map functions such as adding or subtracting a number of
days to a date, determining the number of days between a date, and
determining the weekday to the buttons +, -, *, and /.
You can either implement your own set, or in an emergency use the
Java Set data type to implement your set calculator.
How are you going to do the input? Start with just sets of single
digits. {1, 3} + {1, 4} = {1, 3, 4}. How are you going to map the
functions such as adding, subtraction, or intersecting sets to the
buttons on the calculator?
How do you get your calculator to accept input
of your chosen data type and to display output of the chosen type?
Lab
exercises
Make another new copy of the
Calculator (don't wreck your previous versions!) before you start. Or
you can extend your Calculator to be able to do decimal, hex, and your
chosen data type!
If you are doing the date calculator,
implement the following functions:
input a date
get the calculator to display a String for the weekday
in the window (hint: you will need a button to push)
add a number of days to a date, displaying the new date
subtract a number of days from a date, displaying the new date
subtract two dates, giving the number of days between the dates
If you are doing the set calculator,
implement the following funcitons:
input a set
get the calculator to display the number of elements in the set
(hint: you will need a button to push)
add two sets, displaying the result set (this function is commonly
called the union)
subtract one set from another
calculate the intersection of two sets
The bored can make a power set function.
For
the bored:
Have variations for the date display format:
German, American, ISO
Add buttons to your fancy calculator for
switching locale for the dates. Now include a button that, when pressed,
speaks the number or word currently on the display of your calculator.
Blinking lights are not necessary, but maybe you can make it skinable.
It does look like it is going to rain this weekend though ....
Each member of the pair of you submits the same
report. Remember to include a report on how the pair programming went!
Your reports are due by 22.00 next week.