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

Create a Java class called ResturantBill. An object from this class should have

ID: 3805790 • Letter: C

Question

Create a Java class called ResturantBill. An object from this class should have five instance variables: Name of the restaurant, Cost,Tax,Tip,and Total Cost. The name of the restaurant and cost of the bill(before tax and tip) will be assigned a value that the user will pass into the constructor. The tax,tip,and total cost will start with the value of 0. You will need to create get methods for each of your indtance variables.You will also need the following methods:

Method that calculates tax amount assuming 7% tax(no parameters needed).

Method that calculates the tip amount . This method will accept a String parameter that will represent whether the person was Totally Satisfied,Satisfied or Dissatisfied. The tip will be 20%,15%,or 10% respectively.

Method that calculates the total cost of the bill(no parameters needed).

Method that returns the cost, tax amount,tip and total cost properly formatted.

Your Tester program should ask the user what resturant they ate at and how much the original cost of the meal was. When you create the resturant bill object you should use the variables input by the user as the parameters for the constructor. Once you have created the object you should call all necessary methods to calculate the total cost of the bill. You should print out all of the costs that make up the total blii for the user to see.(For the tip calculator method you will have to ask the user if they were totally satisfied/satisfied/dissatisfied, save this in a variable, and pass that variable as the parameter to the method

Explanation / Answer

ResturantBill.java

public class ResturantBill {

   private String restaurant_name;
   private double cost;
   private double tax;
   private double tip;
   private double totalCost;
   public ResturantBill(String restaurant_name, double cost) {
      
       this.restaurant_name = restaurant_name;
       this.cost = cost;
       this.tax=0;
       this.tip=0;
       this.totalCost=0;
   }
   public String getRestaurant_name() {
       return restaurant_name;
   }

   public double getCost() {
       return cost;
   }

   public double getTax() {
       return tax;
   }

   public double getTip() {
       return tip;
   }

   public double getTotalCost() {
       return totalCost;
   }
public double calTax()
{
   double taxAmt=getCost()*0.07;
   return taxAmt ;
}
public double calTip(String message)
{
   double amount=0.0;
   if(message.equals("totally satisfied"))
   amount=getCost()*0.20 ;
   else if(message.equals("satisfied"))
   amount=getCost()*0.15;
   else if(message.equals("dissatisfied"))
   amount=getCost()*0.10;
  
   return amount;
}
public double calTotalCost()
{

   double total=0.0;
   total=getCost()+calTax();
   return total;
}

}

_________________

Test.java

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

public class Test {

   public static void main(String[] args) {

       String name;
       double billAmount;
       String foodReview;
       NumberFormat fmt = NumberFormat.getCurrencyInstance();
       //Scanner object is used to get the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       System.out.print("Enter the name of the Restaurant :");
       name=sc.nextLine();
      
       System.out.print("Enter the Bill Amount :$");
       billAmount=sc.nextDouble();
       sc.nextLine();
       System.out.print("How is the food (totally satisfied/satisfied/dissatisfied) ? ");
       foodReview=sc.nextLine();
      
       ResturantBill tb=new ResturantBill(name,billAmount);
      
       System.out.println(" Welcome to "+name);
       System.out.println("===============");
       System.out.println("::BILL RECEIPT ::");
       System.out.println("===============");
       System.out.println("Bill amount: "+fmt.format(tb.getCost()));
       System.out.println("Tax: "+fmt.format(tb.calTax()));
       System.out.println("Tip: "+fmt.format(tb.calTip(foodReview)));
       System.out.println("----------------");
       System.out.println("Total Bill: "+fmt.format(tb.calTotalCost()+tb.calTip(foodReview)));
      
      

   }

}

_____________________

Output:

Enter the name of the Restaurant :Taj Mahal
Enter the Bill Amount :$450
How is the food (totally satisfied/satisfied/dissatisfied) ? totally satisfied

Welcome to Taj Mahal
===============
::BILL RECEIPT ::
===============
Bill amount:   $450.00
Tax:       $31.50
Tip:       $90.00
----------------
Total Bill:   $571.50

_______________Thank You