Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package com.lec.test; public interface Order { public double getPrice ( FoodItem item ) ; public double tax ( double price ) ; / / 1
package com.lec.test;public interface Order public double getPriceFoodItem item; public double taxdouble price; tax
package com.lec.test;public class FoodItem private String menuId; private String name; private int quantity; public FoodItemString menuId, String name, int quantity this.menuId menuId; this.name name; this.quantity quantity; public String getMenuId return menuId; public void setMenuIdString menuId this.menuId menuId; public String getName return name; public void setNameString name this.name name; public int getQuantity return quantity; public void setQuantityint quantity this.quantity quantity;
package com.lec.test;import java.util.List;public class OrderCart private Order order; private List items; public Order getOrder return order; public void setOrderOrder order this.order order; public List getItems return items; public void setItemsList items this.items items; public double getTotalPrice double totalAmount ; forFoodItem item:items System.out.printlnitemgetName item.getQuantity; totalAmount order.getPriceitem item.getQuantity; totalAmount totalAmount order.taxtotalAmount; return totalAmount;The code above implement a McDonalds Ordering System Each branch can create its own menu but unfortunately, the price is determined by the head office. FoodItem class is designed to create a menu but you should use Order interface to get the price of each menu. Also you can ask amount of tax using the same interface
Implementing the Order Interface is not your task. Your task is to test the getTotalPrice method. Keep in mind, to test getTotalPrice you should ask a price to head office using the Order interface
Test the getTotalPrice method using Mockito
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started