Answered step by step
Verified Expert Solution
Link Copied!

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 getPrice(FoodItem item); public double tax(double price);//10% tax}
package com.lec.test;public class FoodItem { private String menuId; private String name; private int quantity; public FoodItem(String menuId, String name, int quantity){ this.menuId = menuId; this.name = name; this.quantity = quantity;} public String getMenuId(){ return menuId;} public void setMenuId(String menuId){ this.menuId = menuId;} public String getName(){ return name;} public void setName(String name){ this.name = name;} public int getQuantity(){ return quantity;} public void setQuantity(int 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 setOrder(Order order){ this.order = order;} public List getItems(){ return items;} public void setItems(List items){ this.items = items;} public double getTotalPrice(){ double totalAmount =0.0; for(FoodItem item:items){ System.out.println(item.getName()+""+ item.getQuantity()); totalAmount += order.getPrice(item)* item.getQuantity();} totalAmount = totalAmount + order.tax(totalAmount); return totalAmount;}}1.The code above implement a McDonald's 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)
2.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)
3.Test the getTotalPrice method using Mockito

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_2

Step: 3

blur-text-image_3

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

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions