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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!