//*******************************************************************
//
//   Eating.java          In Text          Application
//
//   Authors:  Lewis and Loftus
//
//   Classes:  Eating
//             Food
//             Pizza
//
//*******************************************************************


//-------------------------------------------------------------------
//
//  Class Eating contains the driver of a program that indirectly
//  uses variables and methods that are not inherited.
//
//  Methods:
//
//     public static void main (String[] args)
//
//-------------------------------------------------------------------

class Eating {

   //===========================================================
   //  Instantiates a Pizza object and invokes a public
   //  method.
   //===========================================================
   public static void main (String[] args) {

      Pizza special = new Pizza (275);

      System.out.println ("Calories per serving: " +
         special.calories_per_serving());

   }  // method main

}  // class Eating

//-------------------------------------------------------------------
//
//  Class Food represents a food item with methods to compute total
//  calories and calories per serving.
//
//  Constructors:
//
//     public Food (int num_fat_grams, int num_servings)
//
//  Methods:
//
//     private int calories()
//     public int calories_per_serving()
//
//-------------------------------------------------------------------

class Food {

   final private int CALORIES_PER_GRAM = 9;
   private int fat;
   protected int servings;

   //===========================================================
   //  Sets up a food item with the specified number of fat
   //  grams and servings.
   //===========================================================
   public Food (int num_fat_grams, int num_servings) {

      fat = num_fat_grams;
      servings = num_servings;

   }  // constructor Food

   //===========================================================
   //  Computes and returns the number of calories in this
   //  food item due to fat.  Note that this is a private
   //  method.
   //===========================================================
   private int calories() {

      return fat * CALORIES_PER_GRAM;

   }  // method calories

   //===========================================================
   //  Computes and returns the number of fat calories per
   //  serving.  This is a public method that invokes a private
   //  method.
   //===========================================================
   public int calories_per_serving() {

      return (calories() / servings);

   }  // method calories_per_serving

}  // class Food

//-------------------------------------------------------------------
//
//  Class Pizza represents a specific kind of food item.
//
//  Constructors:
//
//     public Pizza (int amount_fat)
//
//-------------------------------------------------------------------

class Pizza extends Food {

   //===========================================================
   //  Sets up a pizza with the specified amount of fat and
   //  assuming eight servings.
   //===========================================================
   public Pizza (int amount_fat) {

      super (amount_fat, 8);

   }  // constructor Pizza

}  // class Pizza


