A good answer might be:

New Example: Fat Calculator

The answer is (I hope) obvious. It is a good idea to keep the GUI code and the application code in separate modules to help in debugging and understanding the program. This is also helpful if you later need to make changes to the program, say changing it from an application to an applet. The application code can be carried over without change.

Let us develop another GUI application. The USDA recommends that the food you eat have less than 30% of its total calories in fat. This application calculates the percentage of calories that come from fat, given the number of grams of fat and the number of calories per serving of a food. Fat contains 9 calories per gram.

  1. Input:
    • Calories per serving.
    • Grams of fat per serving.
  2. Calculation:
    • percent = ( (fat * 9) / calories ) * 100
  3. Output:
    • percent of fat from calories

QUESTION 8:

What data type should be used for the variables and for the calculation?