Question
Revise this program so that pizzaCount represents the correct number of pizzas where we have n ingredients, as specified by the user. Put some comments
Revise this program so that pizzaCount represents the correct number of pizzas where we have n ingredients, as specified by the user. Put some comments in your code (inside the 'for' loop) that show, in broad strokes, how we are going to determine which of the ingredients are on a particular pizza. We can assume that 0 means a plain pizza, and that (pizzaCount-1) means the fully loaded pizza. But, how are we going to determine which ingredients are on (just as an example) pizza #9 ? Put comments in the code (or go ahead and write code if you are adventurous!) to indicate your design plan for this.
The following is what I have so far. I have prompted the user to enter different types of topping. I need help with deriving all the possible combinations of those pizza toppings and actually declare which combinations numbers have which toppings. import java.util.*; import java.util.ArrayList; public class pizzaCount { public static void main(String args[]) // the 'main' method of the program { int i; // a variable to hold a whole number, or integer int n; // ingredients int pizzaCount=0; // total possible pizzas String ingredients; System.out.println("Welcome to the Pizza Food Cost Program!"); System.out.println("How many ingredients do you have to work with?"); n = InputUtils.GetInt(); String[] storage = new String [n]; int nums[]; nums = new int[n]; for ( i = 0; i < n; i++ ) { System.out.println(" Please enter your ingredients: "); ingredients = InputUtils.GetStr(); } pizzaCount = (int) Math.pow(2,n); System.out.println("With the given number of ingredients, there are several combinations you can choose!"); // let's loop pizzaCount times in order to analyze each possible pizza... for ( i = 0; i < pizzaCount; i++ ) { System.out.println("Looking at pizza number: " + i ); // this is how we can print stuff out if (i == 0) { System.out.println("Pizza " + i + " is Plain Pizza"); } } } }
Following is my code that prompts user string, double or int input:
import java.io.*;
public class InputUtils { public static int GetInt() { int IntIn = 0;
// set up the keyboard input stuff... BufferedReader reader; reader = new BufferedReader(new InputStreamReader(System.in));
try { IntIn = Integer.parseInt(reader.readLine()); } catch (IOException ioe) { System.out.println("Error receiving integer input."); return(-1); }
return(IntIn); } // end GetInt()
public static double GetDbl() { double DblIn = 0;
// set up the keyboard input stuff... BufferedReader reader; reader = new BufferedReader(new InputStreamReader(System.in));
try { DblIn = Double.parseDouble(reader.readLine()); } catch (IOException ioe) { System.out.println("Error receiving double input."); return(-1); }
return(DblIn); } // end GetDbl()
public static String GetStr() { String StrIn = "";
// set up the keyboard input stuff... BufferedReader reader; reader = new BufferedReader(new InputStreamReader(System.in));
try { StrIn = reader.readLine(); } catch (IOException ioe) { System.out.println("Error receiving string input."); return(""); }
return(StrIn); } // end GetStr() } // end InputUtils class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started