Tip Top Bakery has requested a software applcation they can use to help manage t
ID: 664878 • Letter: T
Question
Tip Top Bakery has requested a software applcation they can use to help manage their business. To get started, we need to express in code some of the basic entities the business uses. In this assignment, we will model a sandwich, which consists of two pieces of bread and some filling. Each entity should be implemented as a class, which means that we will need a Bread, Filling, and Sandwich class. Let's tackle them one-at-a-time and put them all together at the end.
To begin, add a Bread class to the .java file that contains the items indicated in the UML diagram shown below:
---------------
UML class diagrams are divided into three sections. The first section contains the name of the class. The second section lists all the fields contained within the class. Each field has a name and a data type. The name is displayed first, then the colon, and then the data type. The third section contains all of the methods of the class. For a given method, the name comes first followed by a set of parenthesis where arguments may or may not be passed to the method. Methods that require arguments show them with the data type first, a space, and then the name of the parameter. After the closing parenthesis and colon, the return data type of the method is displayed. All methods with the exception of constructors (which never have return types) have this notation. Methods that do not return values use the void data type. A minus sign (-) indicates that the item is private, whereas a plus sign (+) indicates it is public. You will notice that in all of the classes in this course, the fields are always private and the methods are usually public. I say usually because every once and a while you may want to create a helper method that you don't expose to the outside world but that other methods within the same class can use. Methods like this are usually referred to as helper methods.
--------------
To build the Bread class, add the fields and methods to the class as shown in the diagram.The constructor for this class should accept the filling type and calories per serving. Then, within the body of the method, call the setter methods to store them.
Objective 2: Build the Filling class
Next, add a Filling class to the .java file that contains the items indicated in the UML diagram shown below:
To build the class, add the fields and methods shown in the UML diagram. The constructor should accept a filling typeand a calories per serving and call the setter methods to store them.
Objective 3: Build the Sandwich class
Next, create a Sandwich class in the .java file that contains the items indicated in the UML diagram shown below:
This class will take advantage of composition, which is where one class contains members from another class. In this case, the Sandwich will contain a Bread object that represents the two slices of bread (we assume both slices are the same), and a Filling object. Add the fields shown in the UML diagram as well as the methods. Observe the following:
When you create the fields, define them using the appropriate type, i.e. private Bread bread;
The constructor should accept a bread type, calories per slice, filling type, and a calories per serving. It should then create new Bread and Filling objects, passing the relevant variables to their constructors. For instance, you would do this for the filling: filling = new Filling(fillingType, caloriesPerServing); where filling is the name of the field and both fillingType and caloriesPerServing are parameters passed in to the constructor.
Notice that the Sandwich class has another method named getTotalCalories(). This method should calculate and return the total number of calories for the sandwich by adding the calories for a two slices of bread (assuming both slices are the same) and the calories for the topping (assuming only one serving is needed).
Objective 4: Build the TipTopBakery class
Finally, let's add some code to the main() method of the TipTopBakery class to complete the assignment. Within themain() method, prompt the user for the type of bread they want for the sandwich, how many calories there are per slice for that type of bread, the topping they want, and the calories per serving for the filling. Store each item into a local variable. Then, create a Sandwich object, passing in the four parameters it requires. Remember that theSandwich object will build the Bread and Filling objects for you. All you need to do next is to display a message to the user that has this format:
This sandwich has two slices of ____ bread ( ___ calories per slice) with ____ filling ( ___ calories per serving). The total number of calories for the sandwich is _____.
The blanks should be filled in with the actual values. To get those values, you must begin with your Sandwich object. Let's suppose you call that variable mySandwich. If you need to access the bread type, you can callmySandwich.getBread().getBreadType(). If you need the calories per serving of the filling, you can callmySandwich.getFilling().getCostPerServing(). You can use this approach to get all the data you need in order to construct the string shown above. Another approach is to create properties in the Sandwich class that drill down into the appropriate object for you. And so, for instance, the Sandwich class could have getBreadType() andgetBreadCalories() as well as getFillingType() and getFillingCalories() methods.
Bread Class - breadType String caloriesPerSlice: integer + Bread (string breadType, integer caloriesPerslice) + getBreadType : String + setBreadType (String breadType) voicd + getCaloriesPerSlice) integer + setcaloriesPerSlice(integer calories) voidExplanation / Answer
public class Product { private int productType; private int productPrice; public Product () {} public void setProductPrice(int cents) { if(productType == 1) { cents = 345; } } public int getProductPrice(int cents) { if(productType == 1) { cents = 345; } return productType*cents; } public String toString() { return productType + ""; } } import java.util.Scanner; public class BallanBakery { public static void main(String[] args) { int itemQ; int productType; Scanner input = new Scanner(System.in); // Print the Welcome sign top astrix for (int x= 0 ; x < 32 ; x++) { System.out.print("*"); } System.out.println();//print empty line System.out.println(" * Welcome to Ballan Bakery * "); System.out.println();//print empty line // Print the Welcome sign botton astrix for (int x= 0 ; x < 30 ; x++) { System.out.print("*"); } System.out.println();//print empty line System.out.println();//print empty line System.out.println();//print empty line // Menu for the Bakery System.out.println(" Today Menue "); System.out.print("~~~~~~~~~~~~~~ "); System.out.println("| 1.Cake |"); System.out.println("| 2.Pie |"); System.out.println("| 3.Bread |"); System.out.println("| 4.Roll |"); System.out.println("| 5.Cookie |"); System.out.println("| 6.Done |"); System.out.print("~~~~~~~~~~~~~~ "); System.out.println();//print empty line System.out.print("Enter the number of the product type : "); productType = input.nextInt(); System.out.print("Enter the quantity purchased : "); itemQ = input.nextInt(); //check the correct input while (itemQRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.