|
|
HTW Berlin
Fachbereich 4
Internationaler Bachelor Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Summer Term 2023
|
Exercise
4: Abstract Data Types
|
Finger Exercises
Please have these completed before coming to
the lab.
- How do Julian Dates work? We discussed this in class. See if you can find more information on the Internet and put your sources in your
report.
Write out the abstract data type that you discussed during class.
- 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 arithmetic methods such as daysBetween, tomorrow
and yesterday.
Lab exercises
These are the required exercises for this week.
Work in groups of two, doing pair programming, and turn in the same report
for each member of the pair. Remember to put your names on the report. You
can continue to use BlueJ, or move to Eclipse or IntelliJ, if you wish.
You will be implementing an abstract data type.
This means that you will make a class that represents the type you are
implementing. If you have different ADTs specified, you have to decide
what you need before you start. The class 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 the 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 the person has 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?
- Since you can calculate Sundays, can you write
a little program to calculate in which years Christmas Eve is on a
Sunday? 2017 was the last one, when is the next one?
- 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 in years??
For the
bored:
- Can you calculate the date for Easter
next year?
- Make an app 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, too...
- 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.
For the
really bored:
- Genios is a service that indexes articles in
very many German newspapers in magazines. It costs money to read the
articles, but you can query the database and scrape the number of
articles per day. Now, wouldn't it be fun to plot how many articles
there are on a particular topic over a certain time period? Here's the result
I got using Python to search for "plagiat*" and "doktor*" for every day,
over a period of 10 years. Now guess what the funny peaks are. Python
already has a built-in + operator for dates, so if you are using Python,
please use your own nextDay function. The query string I used was
"http://www.genios.de/dosearch?explicitSearch=true&q="
+ keywordstr +
"&dbShortcut=%3A2%3AALLEQUELLENNEU-1_%3A2%3AALLEQUELLENNEU&TI%2CUT%2CDZ=&NN%2C"+"AU%2CMM%2CZ2=&CO%2CC2%2CTA%2CKA%2CVA%2CZ1=&Z4=&Z5=&Z3=&timeFilterType=on&DT_from="
+ self.startdate.strftime("%d.%m.%y") + "&DT_to=" +
self.startdate.strftime("%d.%m.%y") +
"&timeFilter=0&x=76&y=8"
Your report is due by 10.00
pm the night before your next lab! As in Informatics 1, We are
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
Prof. Dr. Debora Weber-Wulff
Questions or comments:
<weberwu@htw-berlin.de>
Some rights reserved. CC-BY-NC-SA - Copyright and Warranty