Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

Draw a schematic diagram of I.C. engines and name the parts.

Answered: 1 week ago

Question

Use a three-step process to develop effective business messages.

Answered: 1 week ago