In: Computer Science
Using Java
Calculating the tip when you go to a restaurant is not difficult, but your restaurant wants to suggest a tip according to the service diners receive. Write a program that calculates a tip according to the diner’s satisfaction as follows:
•Ask for bill amount
•Ask for the diners’ satisfaction level using these ratings: 1 = Totally satisfied, 2 = Satisfied, 3 = Dissatisfied.
•If the diner is totally satisfied, calculate a 20 percent tip.
•If the diner is satisfied, calculate a 15 percent tip.
•If the diner is dissatisfied, calculate a 10 percent tip.
•Report the satisfaction level and tip in dollars and cents
Format tips to 2 decimal points; if the bill is 105$ and satisfaction level is 3, then the tip will be $10.50
//Java Program
import java.util.Scanner;
public class Tip {
public static void main(String args[]) {
double bill;
int rating;
double tip=0;
Scanner in = new
Scanner(System.in);
System.out.print("Enter bill amount
: ");
bill = in.nextDouble();
System.out.print("Enter Rating :
");
rating = in.nextInt();
if(rating==1)tip = bill*0.2;
else if(rating==2)tip =
bill*0.15;
else if(rating==3)tip =
bill*0.1;
System.out.printf("Tip amount :
$%.2f",tip);
in.close();
}
}
//screenshot