FHTW Berlin

FHTW Berlin
Fachbereich 4
Internationale Medieninformatik
Info2: Informatik II
Sommersemester 2006


Exercise 1: Arrays, Files, and Dates

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.

  1. In some programming languages, such as Ada, you can define an array of characters:

    someArray : ARRAY ['A' .. 'Z'] of INTEGER;

    and then access the array using a character: someArray['T']. Java does not have this feature. How would you go about making an array in Java for representing counters for the letters 'A' to 'Z'?
  2. Normalization of Strings means transforming all Strings to either uppercase or lowercase before comparing them. Write a method that takes a character as a parameter and returns a normalized version of the character.
  3. 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.
  4. Think up some good test cases for testing a JulianDate collection of classes. 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. Check out some of the arithmetic methods I hope you specified in 3 such as daysBetween, tomorrow and yesterday.  

 


Lab exercises:

These are the required exercises for this week. Work in groups of two, and turn in just one report for the group.

  1. How do you go about reading in characters from a file? Write and test a method that returns the next character in a file. Note that you have to do something with the carriage returns - such as ignoring them - and that you have to decide what to do when there are no characters to be returned.
  2. How do you write a String to a file? How do you write an Integer to a file? An int? How do you create a file, anyway?
  3. Now the fun begins! Write a Java application to read in a file character by character, counting the frequencies with which each character occurs. When there are no more characters, create a file frequency.txt and output the frequencies for each character.
  4. Output a histogram of the character frequencies. A histogram has horizontal lines proportional to the magnitude of the number it represents. For example:
    A : **********
    B : *****
    C : ******
  5. Implement the abstract data type Julian Date.
  6. Now make a little program to 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. Check your program using both of your birthdays. Who is the oldest? Is there a Sunday's Child? .

For the bored:

  1. Make your histogram application display the histogram with vertical lines and input the file name as a parameter.
  2. Make an applet that uses the Julian Date and requests the user to input their birthday. If today is their birthday, then play "Happy Birthday" and display a cake with candles animation on it...
  3. Extend the JulianDate class use a locale to determine the language and date style and then supply a readValidateDate() 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.
  4. (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.
  5. (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 9.30 the morning of 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 2006, 2007 Prof. Dr. Debora Weber-Wulff
All rights reserved.
Questions or comments: <weberwu@fhtw-berlin.de>