Read from the input the number of people (int), average slices per person (double), and cost of one pizza (double). Calculate the number of whole pizzas needed (8 slices per pizza). There will likely be leftovers for breakfast. Hint: Use the Math. ceil() method to round up to the nearest whole number and convert to an integer using explicit typecasting to an integer. Calculate and output the cost for all pizzas.
. Calculate and output the sales tax (7%). Calculate and output the delivery charge (20% of cost including tax).
. Calculate and output the total including pizza, tax, and delivery.
Repeat steps 1 - 3 with additional inputs for Saturday night (one order per line). Maintain and output a separate total for both parties.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for (int i = 0; i < 2; i++) {
System.out.println("\nNumber of peoples:");
int people = in.nextInt();
System.out.println("Average slices per person:");
double averageSlices = in.nextDouble();
System.out.println("Cost of one pizza:");
double cost = in.nextDouble();
int pizzaSlices = (int) Math.ceil(people * averageSlices);
int pizzas = pizzaSlices / 8 + (pizzaSlices % 8 != 0 ? 1 : 0);
double pizzasCost = pizzas * cost;
double saleTax = pizzasCost * 0.07;
double deliveryCharge = (pizzasCost + saleTax) * 0.2;
System.out.println("Cost for all pizzas: " + pizzasCost);
System.out.println("Sale tax: " + saleTax);
System.out.println("Delivery charge: " + deliveryCharge);
System.out.println("Total: " + (pizzasCost + saleTax + deliveryCharge));
}
}
}
Comments
Leave a comment