Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program is a java program where the main point is to build a little on-line

ID: 3688988 • Letter: T

Question

This program is a java program where the main point is to build a little on-line food shop. Try to use methods to complete functions.

Program requirements: A food market store invites you to help them build an on-line food order program. Customers can use this program to order food on-line.

The program should include at least 4 functionalities: 1) Add food in order; 2)Remove food from order; 3) Review order; 4) Check out the order. You can use a menu as a UI (user interface).

Assume there are 4 types of food: Hamburger ($8), Lemonade ($3), Chicken Wing ($1), and Pizza ($6). Customer can order any kinds of food, and any amount of them.

Scenario 1: Costumer A ordered 3 Hamburger and 2 Lemonade, and then removed 1 Hamburger and ordered 5 Chicken wings. Check them out finally.

Scenario 2: Costumer B ordered 10 chicken wings and 1 pizza, and then he reviewed his order,

and then add 1 more pizza. Check them out finally.

i) In the add food in order module, your program may need a menu too to show all sorts of food and their price. The input should be food ID and amount. Your program should record the information to calculate the total fee.

ii) In the review order module, all kinds of food information the customer ordered will be shown. The information includes unit price, amount, subtotal fee, and total fee.

iii) In the remove food from order module, customer can remove food from order. The input should be the food ID and amount. Your program should record the changed information.

iv) In the checking out module, the program will print out the bill (review information and tax fee and checkout fee). Checkout fee= total + tax. Taxfee = total * 7.77%. Taxrate: 7.77%. In addition, you can add other modules, such as customer login module, food delivery module, etc.

Output looks like the following:

This output is just an example. You may make it better.

Hint: You may need to declare several global variables to contain customer's order information, like the quantity of any food, the prices, and so on, so that your methods can use them directly. Or the methods pass the data to each other by parameters and returning data.

Hint: You may need the following methods to be created: functionMenu(), foodMenu(), add FoodToOrder(), removeFoodFromOrder(), reviewOrder(), and checkout().

Hint:In the main method, you may need a

sentinel control led loop to control the whole process.

Hint: Think about the situations that the customers mayinput a wrong character/number.

Explanation / Answer

package cart; import entity.Product; import java.util.*; /** * * @author tgiunipero */ public class ShoppingCart { List<ShoppingCartItem> items; int numberOfItems; double total; public ShoppingCart() { items = new ArrayList<ShoppingCartItem>(); numberOfItems = 0; total = 0; } /** * Adds a <code>ShoppingCartItem</code> to the <code>ShoppingCart</code>'s * <code>items</code> list. If item of the specified <code>product</code> * already exists in shopping cart list, the quantity of that item is * incremented. * * @param product the <code>Product</code> that defines the type of shopping cart item * @see ShoppingCartItem */ public synchronized void addItem(Product product) { boolean newItem = true; for (ShoppingCartItem scItem : items) { if (scItem.getProduct().getId() == product.getId()) { newItem = false; scItem.incrementQuantity(); } } if (newItem) { ShoppingCartItem scItem = new ShoppingCartItem(product); items.add(scItem); } } /** * Updates the <code>ShoppingCartItem</code> of the specified * <code>product</code> to the specified quantity. If '<code>0</code>' * is the given quantity, the <code>ShoppingCartItem</code> is removed * from the <code>ShoppingCart</code>'s <code>items</code> list. * * @param product the <code>Product</code> that defines the type of shopping cart item * @param quantity the number which the <code>ShoppingCartItem</code> is updated to * @see ShoppingCartItem */ public synchronized void update(Product product, String quantity) { short qty = -1; // cast quantity as short qty = Short.parseShort(quantity); if (qty >= 0) { ShoppingCartItem item = null; for (ShoppingCartItem scItem : items) { if (scItem.getProduct().getId() == product.getId()) { if (qty != 0) { // set item quantity to new value scItem.setQuantity(qty); } else { // if quantity equals 0, save item and break item = scItem; break; } } } if (item != null) { // remove from cart items.remove(item); } } } /** * Returns the list of <code>ShoppingCartItems</code>. * * @return the <code>items</code> list * @see ShoppingCartItem */ public synchronized List<ShoppingCartItem> getItems() { return items; } /** * Returns the sum of quantities for all items maintained in shopping cart * <code>items</code> list. * * @return the number of items in shopping cart * @see ShoppingCartItem */ public synchronized int getNumberOfItems() { numberOfItems = 0; for (ShoppingCartItem scItem : items) { numberOfItems += scItem.getQuantity(); } return numberOfItems; } /** * Returns the sum of the product price multiplied by the quantity for all * items in shopping cart list. This is the total cost excluding the surcharge. * * @return the cost of all items times their quantities * @see ShoppingCartItem */ public synchronized double getSubtotal() { double amount = 0; for (ShoppingCartItem scItem : items) { Product product = (Product) scItem.getProduct(); amount += (scItem.getQuantity() * product.getPrice().doubleValue()); } return amount; } /** * Calculates the total cost of the order. This method adds the subtotal to * the designated surcharge and sets the <code>total</code> instance variable * with the result. * * @param surcharge the designated surcharge for all orders * @see ShoppingCartItem */ public synchronized void calculateTotal(String surcharge) { double amount = 0; // cast surcharge as double double s = Double.parseDouble(surcharge); amount = this.getSubtotal(); amount += s; total = amount; } /** * Returns the total cost of the order for the given * <code>ShoppingCart</code> instance. * * @return the cost of all items times their quantities plus surcharge */ public synchronized double getTotal() { return total; } /** * Empties the shopping cart. All items are removed from the shopping cart * <code>items</code> list, <code>numberOfItems</code> and * <code>total</code> are reset to '<code>0</code>'. * * @see ShoppingCartItem */ public synchronized void clear() { items.clear(); numberOfItems = 0; total = 0; } } - See more at: https://netbeans.org/projects/samples/sources/samples-source-code/content/samples/javaee/AffableBean/src/java/cart/ShoppingCart.java#sthash.YLidTBj9.dpuf

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote