# Chapter 64 Programming Exercises

## Exercise 1 — Ideal Weight Calculator with a Slider

Write the ideal weight calculator so that height in inches is entered by using a slider. 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

Set an action command for each radio button using `setActionCommand(String)`.

Add an action listener for each button using `addActionListener()`.

Add a change listener for the slider using `addChangeListener()`.

The ideal weight should be displayed in a text field when the user changes either a radio button or the slider.

Pick initial settings for the buttons and slider. When the program starts up display the ideal weight for those settings.

## Exercise 2 — Cookie Calculator

Rewrite the program from chapter 13 that helps the user decide to buy cookies.

```import java.util.Scanner ;
{
public static void main (String[] args)
{
Scanner scan = new Scanner( System.in );
int hunger, look, smell ;

System.out.print("How hungry are you?            (1-10): ");
hunger = scan.nextInt();

System.out.print("How nice do the cookies look?  (1-10): ");
look   = scan.nextInt();

System.out.print("How nice do the cookies smell? (1-10): ");
smell  = scan.nextInt();

if ( (hunger + look + smell ) > 15 )
else
}
}
```

Use three sliders with ranges 1 through 10 for the three parameters. Write the decision to a `JTextField`.

## Exercise 3 — Cricket Temperature Calculator

The snowy tree cricket chirps faster the hotter it gets. In the eastern United States, the temperature in Fahrenheit can be estimated by adding 40 to the number of chirps in 13 seconds. In the west, add 38 to the number of chirps in 12.5 seconds.

```public void setValue(int n)