For the following exercises, use the incremental development methodology to implement the program. For each exercise, identify the program tasks, create a design document with class descriptions, and draw the program diagram. Map out the development steps at the start. Present any design alternatives and justify your selection. Be sure to perform adequate testing at the end of each development step.

Write a program that teaches children how to read a clock. Input the hour and minute. Accept only numbers between 0 and 12 for hour and between 0 and 59 for minute. Print out an appropriate error message for an invalid input value. Draw a clock that looks something like this:

To draw a clock hand, you use the drawLine method of the Graphics class. The endpoints of the line are determined as follows:

The value for constant K determines the length of the clock hand. Make the K larger for the minute hand than for the hour hand. The angle of the minute hand is computed as

and the angle of the hour hand is computed as

where Hour and Minute are input values. The values 6.0 and 30.0 designate the degrees for 1 min and 1 h (i.e., the minute hand moves 6 degrees in 1 min and the hour hand moves 30.0 degrees in 1 h). The factor converts a degree into the radian equivalent.

You can draw the clock on the content pane of a frame window by getting the content pane’s Graphic object as described in the chapter. Here’s some sample code:

Note: Please refer to the Hints, Tips, & Pitfalls box on p. 258 about putting a delay in the program so the drawing appears on the window. Also, please refer to the You Might Want to Know box on p. 259 if you want the drawing to remain on the window (instead of disappearing when the window is minimized, for example).