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

Answer:

No. This calculation is done with integer arithmetic. It is likely that (fatGrams * 9) is less than calories, so the division would produce zero.

GUI Design

Here are the variables and the graphical component each corresponds to:

 GUI ComponentGUI Method
int calories JTextField getText()
int fatGrams JTextField getText()
double percent JTextField setText()

Each JTextField will have a JLabel and the whole GUI will have 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, the listener was "fired" and ran the application.

QUESTION 10:

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