FHTW Berlin Medieninformatik

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


Exercise 8: Fun with Calculators - Week 2

Finger exercises
  1. We are then going to make a calculator for a different data type that just ints. Choose either a rational number calculator or a date calculator or a set calculator. Of course, the bored are welcome to implement all three or find fascinating new data types to use a calculator with!
    1. If you are going to do a rational number calculator, then you will want to prepare by either polishing your Ratio class or selecting a nice one from a friend. Do remember to give credit to the authors! Make sure that you can read and write Ratios,as well as add, subtract, multiply and divide them. This might be a good time to get the normal form working using the ggT Algorithm you had in Mathematics I.
    2. If you are going to do a date calculator, then 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 (JulianDate base, int days); if necessary. 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 symbols +, -, *, and /.
    3. You can either implement your own set, or 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}. Can you implement union, intersection, disjunction? Other interesting and fun functions?
       

Lab exercises

  1. Make another new copy of the Calculator in Eclipse in a new project (don't wreck the version you just got working last week).
  2. Work on the ButtonHandler to get the calculator to accept input of your chosen data type and to display output of the chosen type. If you are doing the date calculator, get the calculator to display a String for the weekday in the window. Rationals should always be displayed in proper reduced form (1/2 instead of 2/4), dates can be displayed either in European, American, or ISO form.
  3. Implement one function, for example the addition of two rationals, displaying the result as a rational, or subtracting two dates from each other to determine the number of days in between them, or set addition. This is the minimum you need to get working.
  4. But since it really is very easy, if you have been working object-orientedly and not stuffing everything into classes called Martian or MeToo, you could go on and implement the rest of the functions for fun and profit.

For the bored:

  1. Add buttons to your fancy calculator for displaying the decimal value for rational numbers or 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 ....
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