I need help with this problem. Your friend owns a local eating establishment and
ID: 3846179 • Letter: I
Question
I need help with this problem.
Your friend owns a local eating establishment and needs your help in developing an app that calculates the cost pizza. The app needs to ask the user if they want a thin crust or a thick crust and then the number of toppings. It also needs to ask for the number of pizzas. The program will need to print out the type of pizza, number of toppings and the cost. Use the following table to help you calculate the cost of the pizza: Thin Crust over 5 toppings = exist15.00 3 - 5 toppings = exist12.00 1 - 2 toppings = exist9.50 0 toppings = exist8.00 Thick Crust over 5 toppings = exist18.00 3 - 5 toppings = exist15.00 1 - 2 Toppings = exist12.0 0 toppings = exist10.00 Test data Number of pizzas:3 Pizza Type:Thin Crust Number of toppings:4 Total Cost:exist36.00 Number of pizzas:5 Pizza Type:Thick crust Number of toppings:6 Total Cost:exist90 Number of pizzas:4 Pizza Type:Thin Crust Number of toppings:2 Total Cost:exist38.00Explanation / Answer
import java.util.*;
public class Pizza{
public static void main(String []args){
System.out.println("Please enter number of pizza");
Scanner s = new Scanner(System.in);
int num,type,top;
double cost=0.0,totCost;
num = s.nextInt();
System.out.println("Please enter type of crust you want 1.Thin 2.Thick");
type = s.nextInt();
switch(type)
{
case 1:
{
System.out.println("Please enter number of toppings");
top = s.nextInt();
if(top > 5)
cost = 15;
else if(3 <= top && top <= 5)
cost = 12;
else if(1 <= top && top<= 2)
cost = 9.5;
else if(top==0)
cost = 8;
totCost = cost*num;
System.out.println("Total cost is " + totCost);
break;
}
case 2:
{
System.out.println("Please enter number of toppings");
top = s.nextInt();
if(top > 5)
cost = 18;
else if(3 <= top && top <= 5)
cost = 15;
else if(1 <= top && top <= 2)
cost = 12;
else if(top==0)
cost = 10;
totCost = cost*num;
System.out.println("Total cost is " + totCost);
break;
}
}
}
}