Fill This Form To Receive Instant Help
Homework answers / question archive / Notice that the Sandwich class has another method named getTotalCalories()
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 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 Tip TopBakery class Finally, let's add some code to the main () method of the Tip TopBakery class to complete the assignment. Within the main() 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 the Sandwich 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.