CSCI A201/A597

Problem Set One

Second Summer 2000


Your problem is in QuizSite. Due Friday 11:59pm. Solutions to be posted here Saturday at noon.

1. Write a program that displays your name inside a box on the terminal screen, like this:
+----+
|Dave|
+----+
Do your best to approximate lines with characters like | and +.


2. Write a program that prints a Christmas tree:
   /\
  /  \
 /    \
/      \
--------
  "  "
  "  "
  "  "
Remember to use escape sequences to print the \ and " characters.

3. Write the program that computes the sum of the first ten positive integers.

Hint: write a program of the form:

public class Sum10 
{ public static void main(String[] args) 
  { System.out.println(                ); 
  } 
}

4. Write a program that computes the sum of the reciprocals
1/1 + 1/2 + ... + 1/10
This is harder than it sounds. Try writing the program, and check the results against a pocket calculator. The program's results aren't likely to be correct. Then write the numbers as floating-point numbers, 1.0, 2.0, ..., 10.0, and run the program again. Can you explain the difference in the results. We will explain the phenomenon in the lecture notes.

5. Write a program that constructs a Rectangle object, prints it, and then translates and prints it three more times, so that, if the rectangles were drawn, they would form one large rectangle.


6. The intersection method computes the intersection of two rectangles -- that is, the rectangle that is formed by two overlapping rectangles:
You call this method as follows:
Rectangle r3 = r1.intersection(r2);
Write a program that constructs two rectangle objects, prints them, and then prints their intersection. What happens when the two rectangles do not overlap?

Last updated: June 13, 2000 by Adrian German for A201