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

Calculating a tip when you go to a restaurant based on service if something we a

ID: 3737903 • Letter: C

Question

Calculating a tip when you go to a restaurant based on service if something we all do. However, current tip recommendations are not based on degree of satisfaction. This program should create such a tip calculator. 1. In the Tip class: Create a Tip class. Create an instance variable called satisfactionBating. This variable should be an int. Create a constructor. The constructor sets (initializes) satisfactionBating variable to the value in the parameter. Create a method, salculateBill. It will calculatesa tip, calçUp,and add it to the cost of the meal. The method should have a double argument which you should name bill that represents the cost of the meal before the tip. Create a variable which is a double and called tip. If the satisfactionRating is 1, multiple the bill by 20% and assign it to the variable named tip. If the satisfactioRating is 2, multiple the bill by 15% and assign it to the variable named tip. If the satisfaction Rating is 3, multiple the bill by 10% and assign it to the variable named tip. Add the tip to the bill and return the calculated value. The method should return a double which represents the numeric calculation of the tip + the cost a. b. c. d.

Explanation / Answer

Tip.java

public class Tip {

private int satisfactionRating;

public Tip(int n) {

satisfactionRating=n;

}

public double calculateBill(double bill) {

double tip;

if(satisfactionRating==1) {

tip = (bill % 20)/100;

} else if(satisfactionRating==2) {

tip = (bill % 15)/100;

} else {

tip = (bill % 10)/100;

}

return bill+tip;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote