CS 112b
Spring 1999
Ileana Streinu
Midterm Exam
Part 2
Tuesday, March 2, 1999 1:00 - 2:50pm
Getting organized
- Create a directory Midterm in your public_html directory,
with two subdirectories, Pb1 and Pb2.
- Create an html page called mid.html in Midterm, with links to two other
pages named pb1.html (in Pb1) and pb2.html (in Pb2). Make sure
the permissions are set up correctly.
- Work on Problem 1 in the directory Pb1 and on Problem 2 in
Pb2. The java files should NOT be readable during the two hours of
the exam.
- Before you leave the lab, at 2:50, please turn on the read permissions
on the java files. If you forget, please do so by dinner time
(6:00pm, today, Tuesday) so that I can start grading the exams.
Some advice on how to proceed
- The problems do NOT need sophisticated
solutions. Everything is a slight variation on what we did in
the labs and hwks during the first two weeks of the semester.
If
your code becomes too complex, ask me to make sure you have not
misunderstood the problem.
- To insure you get partial credit even
when the final program does not work as desired,
I recommend that you develop your applets in stages and
save the intermediate versions in separate directories when they
are finished and tested.
- Be generous with comments.
Part of the grade will be based on
how readable and neat your code is.
- In Problem 1, you will be asked to implement the solution that you have
designed for the
4th problem in the morning part of the exam, and add a simple
extra feature (draw the rectangle and the diagonal(s) with
different colors).
The
statement of the morning problem #4 will be repeated on this
handout,
and I will bring to you a copy of
the solution that you have designed in the morning.
Start from there. The
myApplet.java template is available here for you
to copy.
- Problem 2 is a slight modification of a problem that you did in
one of the early homeworks.
Problem 1 (50 points)
The applet has two buttons and responds to mouse
clicks. The buttons are labeled Rectangle and Segment.
If the last button pressed on was Rectangle, the user can
draw a rectangle by click-and-drag. When the user presses the
Segment button, a diagonal of the rectangle (from the top
leftmost corner to the bottom righmost corner) is drawn. Then the
applet will not respond to mouse clicks for drawing rectangles
until the Rectangle button is pressed again.
In the beginning, the applet
behaves as if the Rectangle button has been pressed.
The applet draws only one rectangle at a time. It does not remember what the
user did in the past.
Each time the user draws a
new rectangle, the one that was there before will disappear.
Each time the rectangle button is pressed,
the old one disappears from the screen.
Work under the simplifying assumption that the rectangle is always created
from the upper leftmost corner towards the bottom rightmost corner (otherwise
the code is slightly more complex).
The rectangle drawing is done by click and drag. The user clicks on a
point on the screen, then drags the mouse towards the bottom right part
of the screen and finally releases
the mouse. A rectangle is drawn at all these events.
The upper left corner is the point where the user first clicked
and the lower right corner is
where the mouse is currently being positioned.
The diagonal drawn when the Segment button is pressed goes from
the upper left corner to the bottom right corner of the current
rectangle. Both the rectangle and the diagonal should be drawn, in
this case.
Extra features to be added
- Draw both diagonals of the rectangle.
- Draw the rectangle in black and the diagonals in red.
Problem 2 (50 points)
For this applet, the user clicks and drags with the mouse to draw
rectangles, as before. However, at any time all the
rectangles are redrawn, not just the last one.
Extra feature
(if you finished already, add this extra
feature for a bit of extra credit)
The rectangles are drawn
with alternating colors: the first one is black, the second is
red, then a next one is black again, then a red one follows, etc.
Last modified March 1, 1999.
Ileana Streinu