| CSCI A201/A597Problem Set One Second Summer 2000 |
| 1. |
Write a program that displays your name inside a box on the
terminal screen, like this:
Do your best to approximate lines with characters like+----+ |Dave| +----+ | 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:
|
| 4. |
Write a program that computes the sum of the reciprocals
1/1 + 1/2 + ... + 1/10This 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: Write a program that constructs two rectangle objects, prints them, and then prints their intersection. What happens when the two rectangles do not overlap?Rectangle r3 = r1.intersection(r2); |