Chapter 63 Programming Exercises

Exercise 1 — Ideal Weight Calculator

Write the application part of the ideal weight calculator that is described in this chapter (the first version). Use the approximate formula:

W = H2 / 30 , for female

W = H2 / 28 , for male
where W is the ideal weight in pounds, H is the height in inches

For the height, use the middle of the range for each of the radio button's ranges. Set an action command for each radio button using setActionCommand(String) just as for push buttons. Add an action listener for each button using addActionListener().

Pick initial settings of the buttons and when the program starts up display the ideal weight for those settings. Each time a new button is clicked calculate and display the new ideal weight. If you are actually interested in your ideal weight, search the Web for more accurate calculators.

Click here to go back to the main menu.

Exercise 2 — Ideal Weight with Glue

Finish the graphical interface code that uses glue to separate the two button panels. Experiment with adding more glue, perhaps to the left and right of the button panels, between the buttons, and between the button box and the result panel. Resize the display of the frame to see the effect of glue. Add the application code from exercise 1.

Click here to go back to the main menu.

Exercise 3 — Small, Medium, and Large Frame

An improved ideal weight calculator takes into account the type of (human) frame. Add another panel of radio buttons that allow the user to choose a small, medium, or large frame. Multiply the result of the above ideal weight calculation by 0.95 for small frame, 1.0 for medium frame, and 1.05 for large frame.

Click here to go back to the main menu.