A good answer might be:

Use integer values for input and use double precision for calculation. (It would be OK to use integers for everything).

Application part of the Code

The application part looks much like the previous example, except that now there are two values input from the user. This adds complication to the event listener.

public class percentFat extends JFrame implements ActionListener
{

  int calories ;   // input: total calories
  int fatGrams ;   // input:  grams of fat
  double percent ; // result: percent of calories from fat
    
  public percentFat()  // constructor  
  {  
    . . . . .
  }
   
  // Application method
  public void calcPercent()  
  {
    percent = ( (fatGrams * 9.0) / calories ) * 100.0 ;
  }
   
   
  // GUI code
  . . . . .
   
  public static void main ( String[] args )
  {
    percentFat fatApp  = new percentFat() ;
    
    . . . . .
  }
}  

QUESTION 9:

Is the following calculation accurate?

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