Question

Write a program in JAVA, Scenario: School Cafe is offering a new buffet style dining (“make-believe”)....

Write a program in JAVA, Scenario: School Cafe is offering a new buffet style dining (“make-believe”). It intends to open the Café to the students as well as to their families. There is a need for the dining cafeterias to have a program for the servers to print out the bill or check for each party. The three campuses (Ess, Caton, and Dun) dining halls will use this program. Write a program in JAVA that allows each campus cafe to enter its location at the start of the day and will keep tally of number of tables or bills for the day. Server will be allow to enter the number of adults and number of children at each table and a bill will be printed out showing the cost of the meal for the table. At the start of the program, order number or check number starts at 100 and will increment each time a new order is printed out. The order number cannot be repeated or re-used. If server made an error and the order number needs to be cancelled, the manager must be notified and a void will be manually written on that order and noted void. Requirements: Three Java classes: CalcBill, Bill, Café

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Folder Structure :

code/Cafe.java

code/Bill.java

code/CalBill.java

Cafe.java

package code;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

enum Location {
   ESS, CATON, DUN;
}

public class Cafe {
   private Location location;
   private static double totalBill;
   private static int billNumber = 100;
   private List<Bill> billList;
   private double adultPrice;
   private double childrenPrice;

   public Cafe(Location location, double adultPrice, double childrenPrice) {
       this.location = location;
       this.adultPrice = adultPrice;
       this.childrenPrice = childrenPrice;
       billList = new ArrayList<Bill>();
       System.out.println("The Cafe (" + location + ") billing is starting. Previous total Bill is " + totalBill);
   }

   public Location getLocation() {
       return location;
   }

   public double getTotalBill() {
       return totalBill;
   }

   public void setTotalBill(double totalBill) {
       Cafe.totalBill = totalBill;
   }

   public List<Bill> getBillList() {
       return billList;
   }

   public void addBill(Bill newBill) {
       billList.add(newBill);
       totalBill += newBill.getAmount();
   }

   public void displayBills() {
       Iterator<Bill> iterator = billList.iterator();
       while (iterator.hasNext()) {
           iterator.next().displayBill();
       }
   }

   public static int getBillNumber() {
       return billNumber++;
   }

   public void deleteBill(int billNumber) {
       Iterator<Bill> iterator = billList.iterator();
       Bill temp = null;
       while (iterator.hasNext()) {
           temp = iterator.next();
           if (temp.getBillNumber() == billNumber)
               break;
       }
       if (temp != null) {
           billList.remove(temp);
           totalBill -= temp.getAmount();
       } else
           System.out.println("Invalid Bill !!!");
   }

   public double getAdultPrice() {
       return adultPrice;
   }

   public double getChildrenPrice() {
       return childrenPrice;
   }

}

Bill.java

package code;

public class Bill {
   private int billNumber;
   private int adults;
   private int children;
   private double amount;

   public Bill(int billNumber, int adults, double adultPrice, int children, double childrenPrice) {
       this.billNumber = billNumber;
       this.adults = adults;
       this.children = children;
       this.amount = adults * adultPrice + children * childrenPrice;
   }

   public double getAmount() {
       return amount;
   }

   public int getBillNumber() {
       return billNumber;
   }

   public void displayBill() {
       System.out.println("Bill No. " + billNumber);
       System.out.println("************");
       System.out.println("Adults :\t" + adults);
       System.out.println("Children :\t" + children);
       System.out.println("***********************");
       System.out.println("Total Amount :\t" + amount);
   }
}

CalcBill.java

package code;

import java.util.Scanner;

public class CalcBill {
   public static void main(String args[]) {
       boolean flag = true;
       Location location = Location.ESS;
       Scanner scanner = new Scanner(System.in);
       System.out.println("Good Morning !!!");
       System.out.println("Please Enter your Location :");
       System.out.println("ESS(1), CATON(2), DUN(3)");
       switch (scanner.nextInt()) {
       case 1:
           location = Location.ESS;
           break;
       case 2:
           location = Location.CATON;
           break;
       case 3:
           location = Location.DUN;
       }
       System.out.println("\nEnter per buffet price for adult :");
       double adultPrice = scanner.nextDouble();
       System.out.println("\nEnter per buffet price for children :");
       double childrenPrice = scanner.nextDouble();
       Cafe cafe = new Cafe(location, adultPrice, childrenPrice);
       while (flag) {
           System.out.println(
                   "\nEnter New Bill -> 1\nDelete Previous Bill -> 2\nPrint Today's Total Bill -> 3\nPrint All Bills -> 4\nClose today's account -> 5");
           switch (scanner.nextInt()) {
           case 1:
               int adult, children;
               System.out.println("Enter Number of Adults :");
               adult = scanner.nextInt();
               System.out.println("Enter Number of Children :");
               children = scanner.nextInt();
               Bill bill = new Bill(Cafe.getBillNumber(), adult, adultPrice, children, childrenPrice);
               cafe.addBill(bill);
               break;
           case 2:
               System.out.println("\nEnter The Bill Number to make void");
               cafe.deleteBill(scanner.nextInt());
               break;

           case 3:
               System.out.println("\nTotal Bill : " + cafe.getTotalBill());
               break;
           case 4:
               cafe.displayBills();
               break;
           default:
               flag = false;
           }
       }
       scanner.close();
   }
}

Add a comment
Know the answer?
Add Answer to:
Write a program in JAVA, Scenario: School Cafe is offering a new buffet style dining (“make-believe”)....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java You are to write a program that determines the day of the week for...

    In Java You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program: /** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of...

  • in java PART ONE ================================================== Write a program that will read employee earnings data from an...

    in java PART ONE ================================================== Write a program that will read employee earnings data from an external file and then sort and display that data. Copy and paste the input file data below into an external file, which your program will then read. You will want to use parallel arrays for this program. Modify the select sort algorithm to receive both arrays as parameters as well as the size of the arrays. Use the algorithm to sort your earnings array....

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • Java Project For this assignment, you will write a simulation program to determine the average waiting...

    Java Project For this assignment, you will write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: delete the addfirst, addlast, and add(index) methods and instead include a single add method...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Write a program to help answer questions like the following: Suppose the species Klingon ox has...

    Write a program to help answer questions like the following: Suppose the species Klingon ox has a population of 100 and a growth rate of 15 percent, and the species elephant has a population of 10 and a growth rate of 35 percent. How many years will it take for the elephant population to exceed the Klingon ox population? You can assume that this will happen within 10 years. Use the version of the class Species from Sakai’s Week 7...

  • JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year...

    JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude of storm/ //made up data 2004/Ali/1212/1219/1 2003/Bob/1123/1222/3 1980/Sarah/0123/0312/0 1956/Michael/1211/1223/4 1988/Ryan/0926/1019/ 1976/Tim/0318/1010/0 2006/Ronald/0919/1012/2 1996/Mona/0707/0723/1 2000/Kim/0101/0201/1 2001/Jim/1101/1201/3 Text file Class storm{ private String nameStorm; private int yearStorm; private int startStorm; private int endStorm; private int magStorm; public storm(String name, int year, int start, int end, int mag){ nameStorm = name; yearStorm = year; startStorm...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

  • Need code written for a java eclipse program that will follow the skeleton code. Exams and...

    Need code written for a java eclipse program that will follow the skeleton code. Exams and assignments are weighted You will design a Java grade calculator for this assignment. A user should be able to calculate her/his letter grade in COMS/MIS 207 by inputting their scores obtained on worksheets, assignments and exams into the program. A skeleton code named GradeCompute.java containing the main method and stubs for a few other methods, is provided to you. You must not modify/make changes...

  • In Java, Using arrays. You are going to write a program that will play a solitaire...

    In Java, Using arrays. You are going to write a program that will play a solitaire (one-player) game of Mancala (Links to an external site.) (Links to an external site.). The game of mancala consists of stones that are moved through various buckets towards a goal. In this version of mancala, the user will be able to choose a number of buckets and a number of stones with which to set up the game. The buckets will be created by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT