Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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("\n%-10s%4d%10.2f\n", "PERSON#", "AGE", "TOTALBILL");
- double grandTotal = 0;
- for(int i = 0; i < n; i++)
- {
- System.out.printf("%-10d%4d%10.2f\n", (i + 1), orders[i].getAge(), orders[i].getTotalbill());
- grandTotal = grandTotal + orders[i].getTotalbill();
- }
- System.out.printf("Grand tatal = $ %.2f\n" + grandTotal);
- System.out.print("\nEnter 1 if there is one more family wants to give order: ");
- more = input.nextInt();
- System.out.println();
- }while(more == 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement