INFM 718B
Building the Human - Computer Interface
Fall 2006


Course Description
Syllabus
Reading List
Team Project

Exercise 4

Last updated: Oct 6, 8:49 pm

For this exercise, I again encourage you to work in pairs or in a group. To learn more about Pair Programming, see PairProgramming.com.

1. Working with Strings

Use the Java API documentation for the String class to write a program that manipulates Strings as follows:

  1. Create a String s and assign it the value "The quick brown fox jumps over the lazy dog."
  2. Print the length of the string. It should be 44.
  3. Print the string in all upper case.
  4. Use the replaceAll() method to print this string with "fox" changed to "cat".
  5. Use the indexOf() method to print the position of the letter "x" in this string. The Java docs refer to this as the "index", but don't confuse this with an array index. (The "x" should be at position 18.)
  6. Use the substring() method to extract and print the portion of the string starting at position 31 and ending at position 43. This should display "the lazy dog".
  7. Declare an array of Strings named "wordarray". Initialize this array to the list of words in the string s by calling the split() method, passing it a single space " " as the regular expression. A regular expression is a way of specifying patterns. (We are using it very simply here, to specify a single space. Use a for() loop to print each word on a separate line.) Tip: You can determine the length of the array (i.e., the number of elements in it) by using the length attibute: wordArray.length. This will be useful in your for statement.

2. Working with dates and times

Use the code on page 305-306 of HFJ and the Java API documentation for the GregorianDate class to write a program that does the following:

  1. Display the current date and time in the format: MM/DD/YYYY HH:MM:SS AM/PM. Tip: Make sure you print the month correctly - Java counts months starting from 0.
  2. Display the year, month, and day on separate lines.
  3. Compute and display the date one month from now.
  4. Compute and display the date 30 days from now.
  5. As a challenge, use an array of month names and an array of days of the week to display the date in the form: Friday, October 6.
Remember to import any needed packages at the beginning of your class file. For this exercise, you can put this code in the main() method.

3. Start building the Music Machine

As you are reading chapter 11, build the Music Machine. As you do this, use the Java API documentation to explore the classes used in this application. This will apply material we covered on using the documention, and on using packages and imports.


Bill Kules