Modify the program you wrote in programming challenge 19 so that it reports the
ID: 3552903 • Letter: M
Question
Modify the program you wrote in programming challenge 19 so that it reports the number of pizzas you need to buy for a party if each person attending is expected to eat an average of 4 slices. The program should ask the user for the number of people who will be at the party and for the diameter of the pizzas to be ordered. it should then calculate and display the number of pizzas to purchase. Because it is is impossible to buy a part of a pizza, number of required pizzas should be displaed as a whole number.
Explanation / Answer
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int radius, people; // initialize radius and people variable
Scanner scan = new Scanner(System.in); // Create a new Scanner object
System.out.println("Enter amount of people: ");
people = scan.nextInt(); //people = the next int we get as our input from the scanner
System.out.print("Enter pizza diameter: ");
radius = scan.nextInt() / 2; // radius = diameter divided by 2
scan.close(); // Close the scanner, we are done with it
double area = Math.PI * radius * radius; // area of circle = pi*r^2
double slices = area / 14.125; // slices = area divided by 14.125
double pizza = people * slices / 4; // pizza = people coming to party times the amount of slices you have, divided by 4 since for every 1 person we need 4 slices
System.out.println("Pizzas to be ordered: " + pizza); // print result
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.