Answer to Question #264561 in Java | JSP | JSF for Zach

Question #264561

Program Specifications. Write a program to calculate the cost of hosting three pizza parties on Friday, Saturday and Sunday. Read from input the number of people attending, the average number of slices per person and the cost of one pizza. Dollar values are output with two decimals. For example, System.out.printf("Cost: $%.2f", cost);


Note: this program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress.

Step 1 (2 pts). Read from 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. Calculate and output the cost for all pizzas. Submit for grading to confirm 1 test passes.




1
Expert's answer
2021-11-13T10:47:17-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int people = in.nextInt();
        double slicePerPerson = in.nextDouble();
        double pizzaCost = in.nextDouble();
        int pizzas = (int) Math.ceil((people * slicePerPerson) / 8);
        double cost = pizzas * pizzaCost;
        System.out.println("Pizzas: " + pizzas);
        System.out.printf("Cost: $%.2f\n", cost);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS