Question: In this assignment, you will be creating a Java console application to maintain a daily food journal for a person who is participating in the
In this assignment, you will be creating a Java console application to maintain a daily food journal for a person who is participating in the trendy "Paleo Diet", which is a dietary shift to food items that are either produce (vegetables and fruit) or meat (including seafood). **Note: I'm overgeneralizing a bit here for the purposes of this assignment and I'm not an advocate of the Paleo diet, but it does make for an interesting exercise in Inheritance** According to the Paleo Diet, an individual should limit their carbohydrate intake to 100-150 grams per day. The Paleo food journal will record information about for all the "PaleoFood" that one individual eats in one day, including Produce and "Meat". In this programming exercise, you will be creating 3 classes to represent this data: PaleoFood.java, Produce.java and Meat.java. For our purposes, PaleoFood will be the abstract base (parent) class and Produce and Meat will be the concrete derived (child) classes. _______________________________________________________________________________________________ PaleoFood: This is the abstract parent (base) class of the other two. Ensure that it is serializable. Here are the specifications: Make PaleoFood an abstract class (cannot be instantiated). Create instance variables for name (String), calories (int) and carbohydrates (int). **Be sure that all instance variables can be inherited by the two child classes** Create accessors/mutators for all instance variables. Meat: This one of the concrete child (derived) classes. Ensure that it is Serializable. Here are the specifications: Create instance variable for type (1 represents animal meat, 2 means seafood) (int). Create accessor/mutator for type. Create instance variable for cookingTemp (the temperature, in Fahrenheit, at which the meat should be cooked before consumption. Some meat (e.g. seafood) can be eaten raw, which would be 0 for cookingTemp) (int) Create accessor/mutator for cookingTemp Create a constructor with 4 parameters (name, calories, type, cookingTemp). Initialize all instance variables. For Meat, the carbohydrates should be initialized to 0 (no carbs). Carbohydrates should not appear in the constructor parameter list. Override the equals() method to compare all instance variables for equality. Override the toString() method that displays all fields in the following format: "Type: name, calories, carbohydrates, cookingTemp" (If the type is 1 - animal): Meat: Beef, 650 calories, 0g carbs, 170 degrees F (If the type is 2 - seafood): "Seafood: Ahi, 300 calories, 0g carbs, 0 degrees F" UnknownMeatException: This class is used to indicate the meat type specified is not one of the known types (e.g. Meat or Seafood). It is not part of the inheritance tree, but it is used by the Meat class whenever the meat type is specified. Create class UnknownMeatException to extend the Exception class. Throw this exception in your Meat class whenever the Meat type is changed and not 1 (Meat) or 2 (Seafood). Catch the exception in your FoodJournalDemo when the user is entering new Meat data. Produce: This is the other concrete child (derived) class. Ensure that it is Serializable. Here are the specifications: Create instance variable for organic (boolean). (true represents organic produce, false represents non-organic) Create accessor/mutator for organic Create a constructor with 4 parameters (name, calories, carbohydrates, organic). Initialize all instance variables. Override the equals() method to compare all instance variables for equality. Override the toString() method that displays all fields in the following format: [Organic] Produce: name, calories, carbohydrates, For example: (If organic is true): Organic Produce: Brussels Sprouts, 50 calories, 2g carbs (If organic is false): Produce: Fuji Apple, 150 calories, 12g carbs FoodJournalDemo: in this demo, write a public static void main(String[ ] args) method that performs the following: Maintains an ArrayList
Meat paleoFood E Fields cooking Tempo type E Methods equals get Cooking Temp getType Meat setCookingTemp set Type to String Paleo Food Abstract Class E Fields calories carbohydrates name E Methods getCalories get Carbohydrates getName setCalories set Carbohydrates setName Produce paleoFood E Fields organic E Methods equals get organic Produce set organic to String
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
