Question
import java.util.Arrays; public class Order { private final int orderID; private final int[][] foodQuantity = new int[3][]; public Order(int id) { orderID = id; foodQuantity[0]
import java.util.Arrays;
public class Order {
private final int orderID; private final int[][] foodQuantity = new int[3][];
public Order(int id) { orderID = id; foodQuantity[0] = new int[3]; // burger quantity foodQuantity[1] = new int[2]; foodQuantity[2] = new int[3]; }
public Order(int id, final int numBurgers, final int numSides, final int numDrinks) { orderID = id; foodQuantity[0] = new int[numBurgers]; foodQuantity[1] = new int[numSides]; foodQuantity[2] = new int[numDrinks]; }
public int[] getBurgers() { return foodQuantity[0].clone(); }
public void setBurgers(int[] burgers) { foodQuantity[0] = burgers.clone(); }
public int[] getSides() { return foodQuantity[1].clone(); }
public void setSides(int[] sides) { foodQuantity[1] = sides.clone(); }
public int[] getDrinks() { return foodQuantity[2].clone(); }
public void setDrinks(int[] drinks) { foodQuantity[2] = drinks.clone(); }
public void printOrder(final double[][] unitPrices) { printFoodOrder(unitPrices); double totalA = calculateTotalAmount(unitPrices); double taxA = calculateTaxAmount(unitPrices); double totalBill = calculateFinalBill(unitPrices);
System.out.println("Total amount: " + totalA); System.out.println("Taxes: " + taxA); System.out.println("Final Bill: " + totalBill);
}
public void printFoodOrder(final double[][] unitPrices) {
System.out.println("Burgers: " + Arrays.toString(this.getBurgers())); System.out.println("Drinks: " + Arrays.toString(this.getDrinks())); System.out.println("Sides: " + Arrays.toString(this.getSides()));
}
public double calculateTotalAmount(final double[][] unitPrices) { int numFoodTypes = unitPrices.length; double totalAmount = 0; for (int i = 0; i < numFoodTypes; i++) { int numFoods = unitPrices[i].length; for (int j = 0; j < numFoods; j++) { totalAmount += foodQuantity[i][j] * unitPrices[i][j]; } } return totalAmount; }
public double calculateTaxAmount(final double[][] unitPrices) { final double taxRate = 0.05; double taxA = calculateTotalAmount(unitPrices) * taxRate; return taxA; }
public double calculateFinalBill(final double[][] unitPrices) { double finalBill = calculateTotalAmount(unitPrices) + calculateTaxAmount(unitPrices); return finalBill; } }
import java.util.Arrays; import java.util.Scanner;
public class OrderTest {
public static void main(String[] args) { //create a customer order
//Prompt user to enter types of foods and quantity of foods. for example have 3 types of foods
//burger(chicken, beef, fish). Sides(fries, chips), Drinks(soda, juice, coffee)
final double[][] unitPrices = {{4.99, 3.99, 5.99}, {1.99, 2.49}, {2.25, 1.50, 1.99}};
Scanner scanner = new Scanner(System.in);
System.out.print("Welcome to BurgerWorld, Choose your Burger type: Chicken, Beef or Fish: ");
String type = scanner.nextLine(); int[] burgerOrderQty = new int[3];//array of frequency counter?
if (type.equalsIgnoreCase("chicken")) { burgerOrderQty[0] = Integer.parseInt(scanner.nextLine()); } else if (type.equalsIgnoreCase("beef")) { burgerOrderQty[1] = Integer.parseInt(scanner.nextLine()); } else if (type.equalsIgnoreCase("fish")) { burgerOrderQty[2] = Integer.parseInt(scanner.nextLine()); }
System.out.print("Please choose your side and quantity: Side Options are Fries or Chips: "); int[] sideOrderQty = new int[2];
type = scanner.nextLine(); if (type.equalsIgnoreCase("fries")) { sideOrderQty[0] = Integer.parseInt(scanner.nextLine()); }
else if (type.equalsIgnoreCase("chips")) { sideOrderQty[1] = Integer.parseInt(scanner.nextLine()); }
System.out.print("Please choose your drink type and quantity: Coke : Dr Pepper: Orange Juice: Coffee: "); int[] drinkOrderQty = new int[3]; type = scanner.nextLine(); if (type.equalsIgnoreCase("coke")) { drinkOrderQty[0] = Integer.parseInt(scanner.nextLine()); }
else if (type.toLowerCase().contains("pepper")) { drinkOrderQty[1] = Integer.parseInt(scanner.nextLine()); }
else if (type.toLowerCase().contains("juice")) { drinkOrderQty[2] = Integer.parseInt(scanner.nextLine()); } else if (type.toLowerCase().contains("coffee")) { drinkOrderQty[3] = Integer.parseInt(scanner.nextLine()); }
Order customerOrder = new Order(101); customerOrder.setBurgers(burgerOrderQty); customerOrder.setSides(sideOrderQty); customerOrder.setDrinks(drinkOrderQty);
System.out.println(Arrays.toString(customerOrder.getBurgers())); System.out.println(Arrays.toString(customerOrder.getDrinks())); System.out.println(Arrays.toString(customerOrder.getSides())); customerOrder.printFoodOrder(unitPrices); System.out.println(customerOrder.calculateTotalAmount(unitPrices)); System.out.println(customerOrder.calculateTaxAmount(unitPrices)); System.out.println(customerOrder.calculateFinalBill(unitPrices));
customerOrder.printOrder(unitPrices); } }
Welcome to BurgerWorld, Choose your Burger type: Chicken, Beef or Fish: 3 Please choose your side and quantity: Side Options are Fries or Chips: 0 Please choose your drink type and quantity: Coke : Dr Pepper: Orange Juice: Coffee: 3 [0, 0, 0] [0, 0, 0] [0, 0] Burgers: [0, 0, 0] Drinks: [0, 0, 0] Sides: [0, 0] 0.0 0.0 0.0 Burgers: [0, 0, 0] Drinks: [0, 0, 0] Sides: [0, 0] Total amount: 0.0 Taxes: 0.0 Final Bill: 0.0
Language is Java
Why do I keep getting 0 no matter what number I enter?
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