|
|
HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Winter Term 2010/11
|
Exercise 4: Abstract Data Types |
Finger Exercises
Please think through the following questions before coming to the lab. Write down your answers and bring them with you for check-in.
- How do Julian Dates work? Search the Internet for a description and put a link to the source in your report. What methods should a class that offers Julian Dates have? Write an abstract data type that expresses this.
- Think up some good test cases for testing a JulianDate collection of classes. But what is a test case? A pair (input, expected output). That means, that you have to figure out before running the code what the program should output. Include some of the arithmetic methods I hope you specified in the last finger exercise such as daysBetween, tomorrow and yesterday. If you didn't - go back and include them.
Lab exercises:
These are the required exercises for this week. Work in groups of two, and turn in just one report for the group. You will be implementing an abstract data type. This means that you will make a class that represents the type you are implementing. It will have public methods with signatures matching those that you specified - or you need to explain why they had to be changed from what you specified. You may have any number of private methods. Of course, you will have to implement some sort of test harness to see if your implementation works.
- Implement the abstract data type Julian Date you specified in the prelab as a class. If you are missing any methods, explain in your report how you figured out that they were missing, and how you implemented them. Construct a test harness - another class that tests your ADT class and tries to find errors in your implementation.
- Now make a little program that uses your Julian Date class. The program should ask for a birthday and figure out how many days old the person is and what weekday they were born on. If today is their birthday, then write out a special message. If you have lived a number of days that is divisible by 100, print a special message! Check your program using both of your birthdays. Which of you is the oldest? Is there a Sunday's Child?
- A metric system is proposed to reform the calendar. It will have 10 regular days are a week, 10 weeks a month, 10 months a year. Extend your JulianDate class to a class MetricDate that has a method for converting from JulianDate to metric and from metric to JulianDate. How old are both of you on this metric system?
For the bored:
- Make an applet that uses the Julian Date and requests the user to input their birthday. If today is their birthday, then play some "Happy Birthday" song you find on the web. Who has the rights to this music, if you were going to use it online? Or is this in the public domain? You can display a cake with a candles animation on it...
- Extend the JulianDate class to use a locale to determine the language and date style and then supply a readValidDate() method which will conduct a dialogue in the appropriate language as determined by the locale, and not return until a valid date has been entered. Implement at least two different languages.
- (If you have a lot of time on your hands) Extend the JulianDate class to support a third locale, called ISO, which outputs the date in the format yyyy-mm-dd. This format is the ISO standard and is useful since sorting dates on this format will place them into ascending date order.
- (If you have no social life outside of this class) Extend the JulianDate class with toString() methods that respect the locale and give proper month and weekday names in the appropriate languages.
Your report is due by 11.00 pm the evening before your next lab! As in Informatics 1, I am more interested in process than in product, although we are now getting more interested in products as well. Your report should include any collaborators, summarize what you learned, and note the time you invested in this exercise. How many lines of code did you write for each exercise? Record this in your report.
Copyright 2010
Prof. Dr. Debora Weber-Wulff
Questions or comments:
<weberwu@htw-berlin.de>
Some rights reserved. - Copyright and Warranty