Question: Develop a Class Hierarchy in JAVA for the following Food Class Hierarchy: Food Vegetarian food Nonvegetarian food Fruit Vegetable Fish Chicken Data members and member


Develop a Class Hierarchy in JAVA for the following Food Class Hierarchy: Food Vegetarian food Nonvegetarian food Fruit Vegetable Fish Chicken Data members and member functions for these classes Food int Calories, int Fat, int Protein, int Carb, int Sugar int iron Getcalories() Getfood() Returns Fat+Protein+Carb getirono is Leafy() is Watery() Vegetarian Food NonvegetarianFood Vegetable Fruit String type; //leafy, water String type;//dry, water is Dry() is Watery() Create a class Lunch that has Fruit, Vegetable, Fish and Chicken. Create objects for Fruit, Vegetable, Fish and Chicken. For example, Fruit apple = new Fruit(); apple.calories = 50; apple.fat = 5; apple.protein = 10; apple.carb = 20; System.out.println(apple.getCalories ()); System.out.println(apple.getFood()); Vegetable carrot = new Vegetable(); Fish salmon = new Fish(); Assign values for data members and test getCalories() and getFood() methods. Design new methods for other classes too and test them
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
