Question: Please complete the following exercise on Netbeans Java. Here is the code that is given in the picture written: public class Driver { public static

Please complete the following exercise on Netbeans Java.

Please complete the following exercise on Netbeans Java. Here is the codethat is given in the picture written: public class Driver { public

Here is the code that is given in the picture written:

public class Driver {

public static void main(String[] args) {

FoodComponent fi1 = new FoodItem("blueberries", 2.5);

FoodComponent fi2 = new FoodItem("strawberries", 3.5);

FoodComponent fi3 = new FoodItem("egg", 4.5);

FoodComponent fi4 = new FoodItem("chicken", 5.0);

FoodComponent fi5 = new FoodItem("peas", 6.0);

FoodComponent fi6 = new FoodItem("icecream", 7.0);

FoodComponent fc1 = new FoodCategory("frozen");

FoodComponent fc2 = new FoodCategory("meat");

FoodComponent fc3 = new FoodCategory("vegetables");

((FoodCategory)fc1).add(fc2);

((FoodCategory)fc1).add(fc3);

((FoodCategory)fc1).add(fi6);

((FoodCategory)fc2).add(fi3);

((FoodCategory)fc2).add(fi4);

((FoodCategory)fc3).add(fi1);

((FoodCategory)fc3).add(fi2);

((FoodCategory)fc3).add(fi5);

fc1.print(0);

}

}

There is nothing more I can add. This is the complete question. Can you clarify more on what should I provide.

Exercise 2: In a grocery store, there are two kinds of food components food categories such as frozen and food items such as "chicken" Every food component has a name. Every food item has a price. A food category object can contain zero or more food components. For example, a food category object named "frozen can contain other food category objects named "meat", "vegetable" etc.; The "frozen" object can also contain food item objects such as ice-cream. Operations to be supported include: Methods to add and remove food components in the food category class. . double getPrice () method to be supported for all food components. Calling the getPrice () method on a food item object should return its price. Calling the getPrice () method on a food category object should return the sum of the prices of all the food components it contains. void print (int level) method to be supported for all food components. Calling it on a food item object should print its name and its price. The display of the name and the price should be preceded by the level number of tabs. Calling it on a food category object should print its name, the cumulative price of the category, and it should also print the food compo- nents it contains Apply the Composite design pattern to the above design problem. It should have three classes FoodComponent, FoodCategory, and FoodItem. A driver class containing the main method is provided below. Please do not modify any code in this class. public class Driver { public static void main(String[] args) { FoodComponent fil = new FoodItem("blueberries", 2.5); FoodComponent fi2 = new Food Item("strawberries", 3.5); FoodComponent fi3 = new FoodItem("egg", 4.5); FoodComponent fi4 = new Food Item("chicken", 5.0); FoodComponent fi5 = new Food Item("peas", 6.0); FoodComponent fi6 = new FoodItem("icecream", 7.0); FoodComponent fci = new FoodCategory("frozen"); FoodComponent fc2 = new FoodCategory("meat"); FoodComponent fc3 = new FoodCategory("vegetables"); ((FoodCategory)fc1).add(fc2); ((FoodCategory)fc1).add(fc3); ((FoodCategory)fc1).add(fi6); ((FoodCategory)fc2).add(fi3); ((FoodCategory)fc2).add(fi4): ((FoodCategory)fc3).add(fil); ((FoodCategory)fc3).add(fi2); ((Food Category)fc3).add(fi5); fci.print(0); } } When we run the above main method the output should look exactly as follows (i.e. the format should be as shown below): FoodCategory (frozen, 28.5) contains: FoodCategory (meat, 9.5) contains: FoodItem: egg, 4.5 FoodItem: chicken, 5.0 FoodCategory (vegetables, 12.0) contains: FoodItem: blueberries, 2.5 FoodItem: strawberries, 3.5 FoodItem: peas, 6.0 Food Item: icecream, 7.0

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!