Programming



Item Name

(Stopwatch) Design a class named StopWatch. The class contains:

(Stopwatch) Design a class named StopWatch. The class contains: ■ The private data fields startTime and endTime with get methods. ■ A constructor that initializes startTime with the current time. ■ A method named start() that resets the startTime to the current time. ■ A method named stop() that sets the endTime to the current time. ■ A method named getElapsedTime() that returns the...

(Turtle: display a STOP sign) Write a program that displays

(Turtle: display a STOP sign) Write a program that displays a STOP sign, as shown in Figure 3.5b. The hexagon is in red and the text is in white.

(Turtle: draw a star) Write a program that prompts the

(Turtle: draw a star) Write a program that prompts the user to enter the length of the star and draw a star, as shown in Figure 3.5a. (Hint: The inner angle of each point in the star is 36 degrees.)

(Turtle: draw shapes) Write a program that draws a triangle,

(Turtle: draw shapes) Write a program that draws a triangle, square, pentagon, hexagon, and octagon, as shown in Figure 3.6b. Note that the bottom edges of these shapes are parallel to the x-axis. (Hint: For a triangle with a bottom line parallel to the x-axis, set the turtle’s heading to 60 degrees.)

(Turtle: draw the Olympic symbol ) Write a program that

(Turtle: draw the Olympic symbol ) Write a program that prompts the user to enter the radius of the rings and draws an Olympic symbol of five rings of the same size with the colors blue, black, red, yellow, and green, as shown in Figure 3.5c.

(Turtle: paint a smiley face) Write a program that paints

(Turtle: paint a smiley face) Write a program that paints a smiley face, as shown in Figure 3.6a.

(Turtle: triangle angles) Revise Listing 3.2, ComputeAngles.py,

(Turtle: triangle angles) Revise Listing 3.2, ComputeAngles.py, to write a program that prompts the user to enter the three points p1, p2, and p3 for a triangle and display its angles, as shown in Figure 3.7b.

(Turtle: triangle area) Write a program that prompts the user

(Turtle: triangle area) Write a program that prompts the user to enter the three points p1, p2, and p3 for a triangle and display its area below the triangle, as shown in Figure 3.7a. The formula for computing the area of a triangle is given in Exercise 2.14.

§7.7 introduced the Sudoku problem. Write a program that lets

§7.7 introduced the Sudoku problem. Write a program that lets the user enter the input from the text fields in an applet, as shown in Figure 18.1. Clicking the Solve button displays the result.

1. Obtain a copy of the Java program shown in

1. Obtain a copy of the Java program shown in Listing 1.1 from the Web at the location given in the preface. Name the file FirstProgram.java. Compile the program so that you receive no compiler error messages. Then run the program.