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

JAVA use dual arrays Your spouse\'s cousin\'s nephew\'s dog\'s trainer\'s best f

ID: 3719049 • Letter: J

Question

JAVA use dual arrays Your spouse's cousin's nephew's dog's trainer's best friend owns a restaurant. That person is very bad at math and recently discovered that most customers have been significantly undercharged for meals.

You have been approached to create a computer program that will accurately calculate bills for each customer.

Kids, under 5, eat free.

Teens and seniors get a 25% discount.

Also,

Food and beverage is taxed at 5%.

No tax for anything a senior or teen orders and eats.

Every person who eats at this restaurant orders exactly three items. Never greater, never fewer.

The menu is limited:

Menu Item

Price

Soup

2.50

Wings

.15 each

Burger

4.95

Chicken sandwich

5.95

Fries

1.99

Pie

2.95

Ice cream

2.99

Soft drink

1.50

Coffee

1.00

Write a program that will accurately determine a bill.

Programs must be tested. In order to test this program, use the following scenario.

A family stops at the restaurant for lunch. The family is composed of a middle aged mother and father named Bill and Nancy. They have a 2-year old child named Jesse. They are traveling with Nancy's elderly grandmother, Sarah.

Everybody decided to order a burger. Nancy and Jesse order a soft drink. Nancy and Sarah order soup. Bill orders 5 wings. Bill and Sarah order coffee. Jesse orders ice cream.

Run your program one time for each person and determine the grand total this family would owe on their bill.

Menu Item

Price

Soup

2.50

Wings

.15 each

Burger

4.95

Chicken sandwich

5.95

Fries

1.99

Pie

2.95

Ice cream

2.99

Soft drink

1.50

Coffee

1.00

Explanation / Answer

/**
*
*/Restaurent .java

/**
* @author yourname
*
*/
public class Restaurent {

   private static final int TAX_PERCENTAGE=5;
   private static final int DISCOUNT_PERCENTAGE=25;
   private static final int NUMBER_OF_MENU_ITEMS=9;
   // Declare 2D Array to store menu
   public static Object[][] menu = new Object[][] {
           { "Soup", "Wings","Burger", "Chicken sandwich", "Fries", "Pie", "Ice cream", "Soft drink", "Coffee" },
           { 2.50, .15, 4.95, 5.95, 1.99, 2.95, 2.99, 1.50, 1.00 }
           };
  
          
           public static void main(String[] args) {
               //Calculate price for each person and then add to get total
               //Person 1 .Bill
               //Orders 1 burger,
               double burgerCost=determineCost(35, "Burger",1);
              
               //Bill orders 5 wings
               double wingsCost=determineCost(35, "Wings",5);
              
               //Bill orders a Coffee
               double coffeeCost=determineCost(35, "Coffee",1);
              
               double totalForBill=(burgerCost+wingsCost+coffeeCost);
               System.out.println("Total for Bill is "+totalForBill);
              
              
               //Person 2 .Nancy
               //Burger is ordered by every one so no need to call again for burger
              
               // Nancy order a soft drink
               double softdrinkCost=determineCost(35, "Soft drink",1);
              
               // Nancy order a soup
               double soupCost=determineCost(35, "Soup",1);
              
               double totalForNancy=(burgerCost+softdrinkCost+soupCost);
               System.out.println("Total for Nancy is "+totalForNancy);
              
               //Person 3 Jesse
               burgerCost=determineCost(2, "Burger",1);
               // Jesse order a soup , which we can get using soupCost
               soupCost=determineCost(2, "Soup",1);
               //Jesse orders ice cream.
               double iceCreamCost=determineCost(2, "Ice cream",1);
               double totalForJesse=burgerCost+soupCost+iceCreamCost;
               System.out.println("Total for Jesse is "+totalForJesse);
              
              
               //Person 4 Sarah
               burgerCost=determineCost(50, "Burger",1);
               soupCost=determineCost(50, "Soup",1);
               coffeeCost=determineCost(50, "Coffee",1);
              
               double totalForSarah=burgerCost+soupCost+coffeeCost;
               System.out.println("Total for Sarah is "+totalForSarah);
              
              
              
               //Total for all
               double totalAmount=totalForBill+totalForNancy+totalForJesse+totalForSarah;
               System.out.printf(" Total Amount : %f",totalAmount);
               //apply taxes of food
               System.out.println(" Tax : "+taxes(totalAmount));
               totalAmount+=taxes(totalAmount);
              
              
               System.out.printf(" Total Amount with tax: %f",totalAmount);
              
               System.out.printf(" Discount: %f",discount(totalAmount));
              
               System.out.printf(" Final Amount after Discount: %f",totalAmount-discount(totalAmount));
           }
          
          
           //This method will be used to calculate the Bill based on the Person type (child , teen etc.)
           //and Ordered item and quantity.
           public static double determineCost(int age,String orderedItem,int quantity)
           {
               double amount=0.0;
               double cost=0.0;
               if(age<5)
               {
                   //No charges
               }
               else
               {
                   //find the amount of orderedItem from 2D array and then multiply by quantity
                   for (int i=0;i<NUMBER_OF_MENU_ITEMS;i++) {
                       if(menu[0][i].equals(orderedItem))
                       {
                           amount=(double) menu[1][i];
                       }
                  
                   }
                  
                   //multply by quantity
                   cost=amount*quantity;
               }
               return cost;
              
           }
          
          
           //This method will calculate the tax based on the amount
           public static double taxes(double amount)
           {
               return amount*TAX_PERCENTAGE/100;
           }
          
           //This method will calculate the discount based on the amount
           public static double discount(double amount)
           {
               return amount*DISCOUNT_PERCENTAGE/100;
           }
}

Output:

Total for Bill is 6.7
Total for Nancy is 8.95
Total for Jesse is 0.0
Total for Sarah is 8.45


Total Amount : 24.100000
Tax : 1.2049999999999998

Total Amount with tax: 25.305000
Discount: 6.326250
Final Amount after Discount: 18.978750