Would the calculation


    percent = ( (fatGrams * 9) / calories ) * 100 ;
have worked as well?

A good answer might be:

No---the calculation would be carried out with integer arithmetic. The result (an integer) would then be converted to double when it is saved in percent.

GUI Design

Here are the variables and the GUI components they will correspond to:

Application SideGUI ComponentGUI Method
int calories TextField; getText()
int fatGrams TextField; getText()
double percent TextField; setText()

Each TextField will have a Label and the whole GUI will have a Label at the top to act as a heading. All this is much as in the previous example.

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

QUESTION 10:

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

Click Here after you have answered the question