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

Your spouse\'s cousin\'s nephew\'s dog\'s trainer\'s best friend owns a restaura

ID: 3771654 • Letter: Y

Question

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.

1.Kids, under 12, eat free.

2.Teens and seniors get a 25% discount. Teens are anyone from 13 to 18 years old. Seniors are anyone 65 or older.

Also,

1.Food and beverage is taxed at 5%.

2.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 (mid 40s) mother and father named Bill and Nancy. They have a 2-year old child named Jesse. They are traveling with Nancy's 70 year old 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.

Your program should run until the user inputs that there are no more orders. The program should print the total per person and then the grand total. Use methods to display the menu, read the item ordered and read the person’s age.

To earn full credit for this assignment, you MUST create a table for your test cases.

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

Complete Program:

// File: Restaurant.java
public class Restaurant
{
   private final double SOUP = 2.50;
   private final double WINGS = 0.15;
   private final double BURGER = 4.95;
   private final double CHICKENSANDWICH = 5.95;
   private final double FRIES = 1.99;
   private final double PIE = 2.95;
   private final double ICECREAM = 2.99;
   private final double SOFTDRINK = 1.50;
   private final double COFFEE = 1.00;
   private final double DISCOUNT = 0.25;
   private final double TAX = 0.05;
  
   private int age;
   private int soup;
   private int wings;
   private int burger;
   private int chickensandwich;
   private int fries;
   private int pie;
   private int icecream;
   private int softdrink;
   private int cofee;
  
   private double totalbill;
  
   public Restaurant()
   {
       this.age = 0;
       this.soup = 0;
       this.wings = 0;
       this.burger = 0;
       this.chickensandwich = 0;
       this.fries = 0;
       this.pie = 0;
       this.icecream = 0;
       this.softdrink = 0;
       this.cofee = 0;
      
       this.totalbill = 0.0;
   }

   public Restaurant(int age, int soup, int wings, int burger, int chickensandwich, int fries, int pie, int icecream, int softdrink, int cofee)
   {
       this.age = age;
       this.soup = soup;
       this.wings = wings;
       this.burger = burger;
       this.chickensandwich = chickensandwich;
       this.fries = fries;
       this.pie = pie;
       this.icecream = icecream;
       this.softdrink = softdrink;
       this.cofee = cofee;
       calculateTotalbill();
   }
  
   private void calculateTotalbill()
   {
       if(age <= 12)
           totalbill = 0;
       else
           totalbill = soup * SOUP + wings * WINGS + burger * BURGER + chickensandwich * CHICKENSANDWICH
                   + fries * FRIES + pie * PIE + icecream * ICECREAM + softdrink * SOFTDRINK + cofee * COFFEE;
      
       if((age >= 13 && age >= 18) || age >= 65)
           totalbill = totalbill - totalbill * DISCOUNT;
      
       if(age <= 12 || (age > 18 && age < 65))
           totalbill = totalbill + totalbill * TAX;      
   }

   public double getTotalbill()
   {
       return totalbill;
   }
  
   public int getAge()
   {
       return age;
   }
}

// File: RestaurantBill.java
import java.util.*;
public class RestaurantBill
{
   public static void main(String[] args)
   {
       Scanner input = new Scanner(System.in);
       int n;
       int age;
       int soup;
       int wings;
       int burger;
       int chickensandwich;
       int fries;
       int pie;
       int icecream;
       int softdrink;
       int cofee;
       int count;
       int more = 0;
      
       do
       {      
           System.out.print("Number of persons: ");
           n = input.nextInt();      
          
           Restaurant[] orders = new Restaurant[n];
          
           System.out.println("Every person who eats at this restaurant orders exactly three items. Never greater, never fewer.");
          
           for(int i = 0; i < n; i++)
           {
               soup = 0;
               wings = 0;
               burger = 0;
               chickensandwich = 0;
               fries = 0;
               pie = 0;
               icecream = 0;
               softdrink = 0;
               cofee = 0;
               count = 0;
               System.out.println("Enter order for person " + (i + 1) + ":");
              
               System.out.print("Age: ");
               age = input.nextInt();
              
               System.out.print("Soup: ");
               soup = input.nextInt();
              
               if(soup > 0)
                   count++;
              
               System.out.print("Wings: ");
               wings = input.nextInt();
              
               if(wings > 0)
                   count++;
              
               System.out.print("Burger: ");
               burger = input.nextInt();
              
               if(wings > 0)
                   count++;
              
               if(count == 3)
               {
                   System.out.println("You ordered three items. Thank you.");              
                   orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
               }
               else
               {          
                   System.out.print("Chickensandwich: ");
                   chickensandwich = input.nextInt();
                  
                   if(chickensandwich > 0)
                       count++;
                  
                   if(count == 3)
                   {
                       System.out.println("You ordered three items. Thank you.");              
                       orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
                   }
                   else
                   {
                       System.out.print("Fries: ");
                       fries = input.nextInt();
                      
                       if(fries > 0)
                           count++;
                      
                       if(count == 3)
                       {
                           System.out.println("You ordered three items. Thank you.");              
                           orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
                       }
                       else
                       {                  
                           System.out.print("Pie: ");
                           pie = input.nextInt();
                          
                           if(pie > 0)
                               count++;
                          
                           if(count == 3)
                           {
                               System.out.println("You ordered three items. Thank you.");              
                               orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
                           }
                           else
                           {                          
                               System.out.print("Icecream: ");
                               icecream = input.nextInt();
                              
                               if(icecream > 0)
                                   count++;
                              
                               if(count == 3)
                               {
                                   System.out.println("You ordered three items. Thank you.");              
                                   orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
                               }
                               else
                               {                              
                                   System.out.print("Softdrink: ");
                                   softdrink = input.nextInt();
                                  
                                   if(softdrink > 0)
                                       count++;
                                  
                                   if(count == 3)
                                   {
                                       System.out.println("You ordered three items. Thank you.");              
                                       orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
                                   }
                                   else
                                   {                                  
                                       System.out.print("Cofee: ");
                                       cofee = input.nextInt();
                                      
                                       if(cofee > 0)
                                           count++;
                                      
                                       if(count == 3)
                                       {
                                           System.out.println("You ordered three items. Thank you.");              
                                           orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
                                       }
                                       else
                                       {
                                           System.out.println("You ordered less than three items. Give the order again.");
                                           i--;
                                       }
                                   }
                               }
                           }
                       }
                   }
               }          
           }
          
           System.out.printf(" %-10s%4d%10.2f ", "PERSON#", "AGE", "TOTALBILL");
           double grandTotal = 0;
           for(int i = 0; i < n; i++)
           {          
               System.out.printf("%-10d%4d%10.2f ", (i + 1), orders[i].getAge(), orders[i].getTotalbill());
               grandTotal = grandTotal + orders[i].getTotalbill();
           }  
           System.out.printf("Grand tatal = $ %.2f " + grandTotal);  
          
           System.out.print(" Enter 1 if there is one more family wants to give order: ");
           more = input.nextInt();
           System.out.println();
       }while(more == 1);
   }
}