Question

Write a program for a Buffet to display the bill Sor the cashicr The buffet serves a chefs meu with two options 31 50 The to
The Buffet Class Ruffet has these instance variawes String name String location The constrwctor (assigns the returned value f
calcAdultCost sets the category to Adults, calculates the cost of the adult meals, sets the meal Price, and sets and retums
Write a program for a Buffet to display the bill Sor the cashicr The buffet serves a chef's meu with two options 31 50 The total adu bill is roduced by $5.00 if there are 9 aor more ad $15.00 It is free after the third child maximum of 3 childrm) The program requests the name and zip code ofthe buf1ส and converts the tru The pr- then aceepts the number of adults and children, performs the necessary calculations compues the 6% tax. and displays the bill. Follow the formatting ofthe example below. Enter name of Buffet: Enter zip code: Enter nunber of alults - to stop) Rosedaie 1 you can eat Buf fet at a great price 31-50 $278.50 Childre Subtotal 342.92 Total bil Enter nunber of adults (-2 to stop BuffetDemo should follow this soquence Request the name and zip code ofthe buffet from the usส. Use the Buffet class to set the buffct name and the location but do not display it You will display the buffet information in the wheile loop with the other output Page 1 Project Four The while loop: Requests the namber of meals for adults and children Uses the Bill class to instantiate these objects Uses the Bill class to calculate the adult and child costs Uses the Bill class to calculate the tax The call should look like this: Totals the costs Displays the buffet name and location created carlier using the Buffet class-whe loString method (the title of the bill) Displays the two lines showing the aduh and child costs using the Bill class use the display method Displays the subtotal ef the bill. Displays the tax. Use Bill. T AXRATE to get the current tax rate 40%) from the Bill class and format the value as percentags the total of the You will be coding two classes: Buffet and Bill
The Buffet Class Ruffet has these instance variawes String name String location The constrwctor (assigns the returned value from the settiers to the propartics) Call the setName method to assign a value to mame, using the vallae passed to it (the name of the bufiet as entered by the user.) Call the setLocation method to assign a value to lication, usang the value passed to it (the zip code as entered by the user Zip code must be an intege Buffet contains these methods Project Four Page 2 set Name method changes the name enterod by the wsr so that the first character is uppercase, the rest ofthe chanters are lower case nd-Buf1ส-isruched.This method returns a string . setLocation method uses the zip code omtcred by the ser to detemine the location underline using the Concatenate the he location. In addition, add the Sollowing line:"All yoe can eat Buflet at a grea pricel, This method returns the concatiemated string character, the undarline must be the same size as Use a nested if or switch Code 21204 1237 Amy other valuc Baltimon toString method returns a string that displays the farst four lines of the receipt Here is an example of possible output A11 yo can eat Buf fet at a grest price The Bill Class Set up a final for the tax rate like this: statik final double TANRATE- 06 Bill has these instance variables String categery nt meallty double mealCost double meal Price The constrwctor categery will be set to null. mcalQtyill be passed the mamber of meals ordered forthe alpry. mealCost will be initialized to 0 meal Price will be initialured to. Bill contains these methods
calcAdultCost sets the category to "Adults", calculates the cost of the adult meals, sets the meal Price, and sets and retums the mealCost. calcChildCost sets the category to "Children", calculates the cost of the children's meals, sets the mealPrice, and sets and returns the mealCost. calcTax calculates the tax. Return the calculated tax based on the total sent to this method. Set up the method like this: static double calcTax(double total) display displays the category, mealQty, mealPrice, and mealCost. Format the number accordingly using the currency format. The method header looks like this: public void displayo You will be submitting 3 java files. Any class, variable or method names in bold must be used in your program. Grading: BuffetDemo Class (20 points) Buffet Class (15 points) Bill Class (15 points) Testing and Accuracy (5 points)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/***************************************Buffet.java**********************************/


public class Buffet {

   /*
   * data field
   */
   private String name;
   private String location;

   public Buffet(String name, int location) {

       this.name = setName(name);
       this.location = setLocation(location);
   }

   public String setName(String name) {

       String name1 = name.toUpperCase().charAt(0) + name.substring(1, name.length()).toLowerCase() + " Buffet";

       return name1;

   }

   public String setLocation(int location) {

       String location1 = "";

       switch (location) {
       case 21204:
           location1 = "Township\n" + "--------" + "\nAll you can eat Buffet at a great price!!!";
           break;
       case 21237:
           location1 = "Rosedale" + "\n\t\t\t --------" + "\nAll you can eat Buffet at a great price!!!";
           break;

       default:
           location1 = "Baltimore" + "\n\t\t\t ---------" + "\nAll you can eat Buffet at a great price!!!";
           break;
       }

       return location1;
   }

   @Override
   public String toString() {

       return "\t\t\t"+name + "\n\t\t\t " + location;
   }

}
/*******************************Bill.java*******************************/

import java.text.NumberFormat;

public class Bill {

   /*
   * data field
   */
   static final double TAXRATE = .06;

   private String category;

   private int mealQty;

   private double mealCost;

   private double mealPrice;

   public Bill() {

       this.category = null;
       this.mealQty = 0;
       this.mealCost = 0;
       this.mealPrice = 0;
   }

   public double calcAdultCost(int numberOfAdults) {

       double mealCost;
       this.mealQty = numberOfAdults;
       this.category = "Adults";
       this.mealPrice = 31.50;
       if (numberOfAdults < 9) {

           mealCost = mealPrice * mealQty;
       } else {

           mealCost = mealPrice * mealQty - 5.00;
       }
       this.mealCost = mealCost;
       return mealCost;
   }

   public double calcChildCost(int numberOfChilds) {

       double mealCost;
       this.mealQty = numberOfChilds;
       this.category = "Adults";
       this.mealPrice = 15.00;
       if (numberOfChilds <= 3) {

           mealCost = mealPrice * mealQty;
       } else {

           mealCost = mealPrice * 3;
       }
       this.mealCost = mealCost;
       return mealCost;
   }

   public static double calTax(double total) {
       return total * TAXRATE;
   }

   public void display() {

       NumberFormat f = NumberFormat.getCurrencyInstance();

       System.out.println("\t" + category + "\t\t" + mealQty + "\t" + f.format(mealPrice) + "\t" + f.format(mealCost));
   }
}
/*********************************BuffetDemo.java************************************/

import java.text.NumberFormat;
import java.util.Scanner;

public class BuffetDemo {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);
       double total = 0;
       NumberFormat f = NumberFormat.getCurrencyInstance();
       System.out.print("\tEnter the name of Buffet: ");
       String name = scan.nextLine();
       System.out.print("\tEnter the ZipCode: ");
       int zipCode = scan.nextInt();

       Buffet buffet = new Buffet(name, zipCode);
       int numberOfAdults;
       boolean choice = true;
       do {
           System.out.print("\n\tEnter the number of Adults (-1 to stop).. ");
           numberOfAdults = scan.nextInt();
           if (numberOfAdults < 0) {

               choice = false;
           } else {
               System.out.print("\tEnter the number of Childs: ");
               int numberOfChilds = scan.nextInt();

               Bill adultBill = new Bill();
               Bill childBill = new Bill();

               double adultCost = adultBill.calcAdultCost(numberOfAdults);
               double childCost = childBill.calcChildCost(numberOfChilds);
               total = adultCost + childCost;
               double tax = Bill.calTax(total);
               System.out.println(buffet.toString());
               System.out.println("\t\t\t\tPrice\tTotal");
               adultBill.display();
               childBill.display();
               System.out.println();
               System.out.println("\tSubtotal\t\t\t\t" + f.format(total));
               System.out.println("\tTax (6%)\t\t\t\t" + f.format(tax));
               System.out.println("\n\t\tTotal Bill\t\t\t" + f.format(total + tax));
               System.out.println("\n");
           }
       } while (choice);
   }
}
/************************output************************************/

   Enter the name of Buffet: moNet
   Enter the ZipCode: 21237

   Enter the number of Adults (-1 to stop).. 9
   Enter the number of Childs: 4
           Monet Buffet
           Rosedale
           --------
All you can eat Buffet at a great price!!!
               Price   Total
   Adults       9   $31.50   $278.50
   Adults       4   $15.00   $45.00

   Subtotal               $323.50
   Tax (6%)               $19.41

       Total Bill           $342.91

   Enter the number of Adults (-1 to stop).. -1

Thanks a lot, Please let me know if you have any problem....................

Add a comment
Know the answer?
Add Answer to:
Write a program for a Buffet to display the bill Sor the cashicr The buffet serves a chef's meu with two options 31 50 The total adu bill is roduced by $5.00 if there are 9 aor more ad $15....
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
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
ADVERTISEMENT