go to previous page   go to home page   go to next page
percent = fatGrams * 9 / calories * 100 ;

Answer:

The statement is correct, although you must think carefully about operator precidence and associativity to be sure. It is better to use a few parentheses to make the calculation clear:

percent = ((fatGrams * 9) / calories) * 100 ;

GUI Design

Each JTextField has a JLabel to its left, and the whole GUI has a JLabel at the top to act as a heading. All this is much as in the previous example.

Fat Calculator GUI

There is something different about this GUI, though. The user inputs two values. The calculation should only be carried out when both values are available. With the previous program, the input JTextField had a listener registered for it. When the user typed something and hit enter, an event was "fired" and the listener received it.

QUESTION 11:

(Design Question: ) Will this style work with the current program?