Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment, we will be modeling a Pizza. We'll create a pizza, add ingredients, and then report the nutritional information bases on the ingredients

image text in transcribedimage text in transcribedimage text in transcribed

For this assignment, we will be modeling a Pizza. We'll create a pizza, add ingredients, and then report the nutritional information bases on the ingredients added. This assignment is an example of composition: A Pizza contains ingredients. You'll write two classes: PizzaPie and Ingredient. Details shown in the UML diagram below. Ingredient We are going to use Java's Enum class to model our Ingredient. Enums are useful when we have a list of enumerations or a limited set of values that we want to represent in software. We'll use enums to represent the following ingredients and their calorie count. PizzaPie Class This class represents our Pizza. We'll define a business rule that we will only allow a total of 6 ingredients on the pizza, including the crust. - The is only one constructor. When invoked, it should automatically add Crust to the list of ingredients. - Ingredients will be kept in an ArrayList - The add() method adds an Ingredient to the list. This method should enforce the requirement regarding the number of ingredients. If an ingredient can be added, this method should return boolean true. If an ingredient cannot be added because the limit has been reached, then this method should return false, to indicate that the ingredient was not added. - The remove() method will remove the specified ingredient from the list. Modeling our ingredients as an Enum will make this easy. You just have to call the appropriate method on your arraylist - The getCalories() method returns the number of calories currently in the pizza. - The getNumberofIngredients() returns the number of ingredients in the pizza. - The toString() method should return a list of ingredients in the pizza, and a nutritional statement. - The toString() method should return a list of ingredients in the pizza, and a nutritional statement. - Use a StringBuffer to build a buffer, and then convert that to a String and return it. We typically use StringBuffer or a similar class instead of String when building dynamic text for better performance. - Make the output as similar to the example shown below. In this example, a pizza was created, and pepperoni, sausage and bacon were added. Then the toString() was called. - your logic in the toString() methods should use the getCalories() method to get the total calories. - NOTE: to determine the calories per slice, assume a pizza has 8 slices. Your Pizza Pie has the following ingredients: CRUST PEPPERONI BACON SAUSAGE Nutritional Information: Calories Per Pie: 1900 Calories Per Slice: 237 As always, it's important to test your code. You can write a class to do the testing. This class can create an instance of a PizzaPie, then call the add() method to add ingredients. It can then print out the class by passing the pizzapie instance to System.out.println(). As part of your testing, try adding more than 6 ingredients to verify your logic regarding the size

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions