Task #2 The if-else-if Statement 1. Write an if-else-if statement that lets the computer choose which...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Task #2 The if-else-if Statement 1. Write an if-else-if statement that lets the computer choose which statements to execute by the user input size (10, 12, 14, or 16). For each option, the cost needs to be set to the appropriate amount. 2. The default else of the above if-else-if statement should print a statement that the user input was not one of the choices, so a 12 inch pizza will be made. It should also set the pizza size to 12 and the cost to 12.99. 3. Compile, debug, and run. You should now be able to get correct output for the pizza size and price (it will still have Hand-tossed crust, the output won't look like money, and no discount will be applied yet). Run your program multiple times ordering a 10, 12, 14, 16, and 17 inch pizza. Code Listing 3.1 (PizzaOrder.java) import java.util.Scanner; // Needed for the Scanner class /** */ This program allows the user to order a pizza. public class PizzaOrder { public static void main (String[] args) { // Create a Scanner object to read input. Scanner keyboard new Scanner (System.in); String firstName; boolean discount false; int inches; char crustType; String crust = "Hand-tossed"; double cost = 12.99; final double TAX_RATE= .08; double tax; char choice; String input; String toppings = = "Cheese "; int numberOfToppings = 0; // User's first name. // Flag for discount // Size of the pizza // For type of crust // Name of crust // Cost of the pizza // Sales tax rate // Amount of tax // User's choice // User input // List of toppings // Number of toppings // Prompt user and get first name. System.out.println("Welcome to Mike and " + "Diane's Pizza"); System.out.print ("Enter your first name: firstName = keyboard.nextLine(); "); // Determine if user is eligible for discount by // having the same first name as one of the owners. // ADD LINES HERE FOR TASK #1 // Prompt user and get pizza size choice. System.out.println("Pizza System.out.println(" System.out.println(" System.out.println(" System.out.println(" Size (inches) 10 12 14 16 System.out.println("What size pizza + "would you like?"); System.out.print ("10, 12, 14, or 16 " + " (enter the number only): "); inches keyboard.nextInt (); // Set price and size of pizza ordered. // ADD LINES HERE FOR TASK #2 Cost"); $10.99"); $12.99"); $14.99"); $16.99"); // Consume the remaining newline character. keyboard.nextLine(); // Prompt user and get crust choice. System.out.println("What type of crust "+ "do you want? "); System.out.print(" (H) Hand-tossed, + "1 "1 "(T) Thin-crust, or + "(D) Deep-dish + "(enter H, T, or D): "); input = keyboard.nextLine(); crustType=input.charAt(0); " // Set user's crust choice on pizza ordered. // ADD LINES FOR TASK #3 // Prompt user and get topping choices one at a time. System.out.println("All pizzas come with cheese."); System.out.println("Additional toppings are " + "$1.25 each, choose from: "); System.out.println("Pepperoni, Sausage, "+ "Onion, Mushroom"); // If topping is desired, // add to topping list and number of toppings System.out.print ("Do you want Pepperoni? (Y/N): "); input keyboard.nextLine(); choice input.charAt(0); if (choice == 'Y' || choice == 'y') ( } System.out.print ("Do you want Sausage? (Y/N): "); input keyboard.nextLine(); input.charAt(0); choice numberOfToppings += 1; toppings = toppings + "Pepperoni "; if (choice == 'Y' || choice == ( } } numberOfToppings += 1; toppings = toppings + "Sausage "; System.out.print ("Do you want Onion? (Y/N): "); input keyboard.nextLine(); input.charAt(0); choice if (choice === 'Y' || choice ( 'y') == 'y') numberOfToppings += 1; toppings toppings + "Onion "; System.out.print ("Do you want Mushroom? (Y/N): "); input keyboard.nextLine(); choice input.charAt(0); if (choice == 'Y' || choice == 'y') ( numberOfToppings += 1; toppings toppings + "Mushroom "; } // Add additional toppings cost to cost of pizza. cost = cost+ (1.25 numberOfToppings); // Display order confirmation. System.out.println(); System.out.println("Your order is as follows: "); System.out.println (inches + " inch pizza"); System.out.println (crust + " crust"); System.out.println (toppings); // Apply discount if user is eligible. // ADD LINES FOR TASK #4 HERE // EDIT PROGRAM FOR TASK #5 // SO ALL MONEY OUTPUT APPEARS WITH 2 DECIMAL PLACES System.out.printf("The cost of your order " + "is: $f ", cost); // Calculate and display tax and total cost. tax = cost * TAX_RATE; System.out.printf ("The tax is: $%f ", tax); System.out.printf ("The total due is: $%f ", (tax + cost)); order will be ready. "for pickup in 30 minutes."); System.out.println("Your Task #2 The if-else-if Statement 1. Write an if-else-if statement that lets the computer choose which statements to execute by the user input size (10, 12, 14, or 16). For each option, the cost needs to be set to the appropriate amount. 2. The default else of the above if-else-if statement should print a statement that the user input was not one of the choices, so a 12 inch pizza will be made. It should also set the pizza size to 12 and the cost to 12.99. 3. Compile, debug, and run. You should now be able to get correct output for the pizza size and price (it will still have Hand-tossed crust, the output won't look like money, and no discount will be applied yet). Run your program multiple times ordering a 10, 12, 14, 16, and 17 inch pizza. Code Listing 3.1 (PizzaOrder.java) import java.util.Scanner; // Needed for the Scanner class /** */ This program allows the user to order a pizza. public class PizzaOrder { public static void main (String[] args) { // Create a Scanner object to read input. Scanner keyboard new Scanner (System.in); String firstName; boolean discount false; int inches; char crustType; String crust = "Hand-tossed"; double cost = 12.99; final double TAX_RATE= .08; double tax; char choice; String input; String toppings = = "Cheese "; int numberOfToppings = 0; // User's first name. // Flag for discount // Size of the pizza // For type of crust // Name of crust // Cost of the pizza // Sales tax rate // Amount of tax // User's choice // User input // List of toppings // Number of toppings // Prompt user and get first name. System.out.println("Welcome to Mike and " + "Diane's Pizza"); System.out.print ("Enter your first name: firstName = keyboard.nextLine(); "); // Determine if user is eligible for discount by // having the same first name as one of the owners. // ADD LINES HERE FOR TASK #1 // Prompt user and get pizza size choice. System.out.println("Pizza System.out.println(" System.out.println(" System.out.println(" System.out.println(" Size (inches) 10 12 14 16 System.out.println("What size pizza + "would you like?"); System.out.print ("10, 12, 14, or 16 " + " (enter the number only): "); inches keyboard.nextInt (); // Set price and size of pizza ordered. // ADD LINES HERE FOR TASK #2 Cost"); $10.99"); $12.99"); $14.99"); $16.99"); // Consume the remaining newline character. keyboard.nextLine(); // Prompt user and get crust choice. System.out.println("What type of crust "+ "do you want? "); System.out.print(" (H) Hand-tossed, + "1 "1 "(T) Thin-crust, or + "(D) Deep-dish + "(enter H, T, or D): "); input = keyboard.nextLine(); crustType=input.charAt(0); " // Set user's crust choice on pizza ordered. // ADD LINES FOR TASK #3 // Prompt user and get topping choices one at a time. System.out.println("All pizzas come with cheese."); System.out.println("Additional toppings are " + "$1.25 each, choose from: "); System.out.println("Pepperoni, Sausage, "+ "Onion, Mushroom"); // If topping is desired, // add to topping list and number of toppings System.out.print ("Do you want Pepperoni? (Y/N): "); input keyboard.nextLine(); choice input.charAt(0); if (choice == 'Y' || choice == 'y') ( } System.out.print ("Do you want Sausage? (Y/N): "); input keyboard.nextLine(); input.charAt(0); choice numberOfToppings += 1; toppings = toppings + "Pepperoni "; if (choice == 'Y' || choice == ( } } numberOfToppings += 1; toppings = toppings + "Sausage "; System.out.print ("Do you want Onion? (Y/N): "); input keyboard.nextLine(); input.charAt(0); choice if (choice === 'Y' || choice ( 'y') == 'y') numberOfToppings += 1; toppings toppings + "Onion "; System.out.print ("Do you want Mushroom? (Y/N): "); input keyboard.nextLine(); choice input.charAt(0); if (choice == 'Y' || choice == 'y') ( numberOfToppings += 1; toppings toppings + "Mushroom "; } // Add additional toppings cost to cost of pizza. cost = cost+ (1.25 numberOfToppings); // Display order confirmation. System.out.println(); System.out.println("Your order is as follows: "); System.out.println (inches + " inch pizza"); System.out.println (crust + " crust"); System.out.println (toppings); // Apply discount if user is eligible. // ADD LINES FOR TASK #4 HERE // EDIT PROGRAM FOR TASK #5 // SO ALL MONEY OUTPUT APPEARS WITH 2 DECIMAL PLACES System.out.printf("The cost of your order " + "is: $f ", cost); // Calculate and display tax and total cost. tax = cost * TAX_RATE; System.out.printf ("The tax is: $%f ", tax); System.out.printf ("The total due is: $%f ", (tax + cost)); order will be ready. "for pickup in 30 minutes."); System.out.println("Your
Expert Answer:
Related Book For
Computer Architecture Fundamentals And Principles Of Computer Design
ISBN: 9781032097336
2nd Edition
Authors: Joseph D. Dumas II
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
A company currently sells 8,280 basketballs (units) per year for $25 each. The company can make up to 10,280 basketballs per year. Each basketball made includes $15 In variable costs and $6.50 of...
-
What is meant by "translational" kinetic energy?
-
Write one or two paragraphs giving reasons for choosing a particular method of solving the following problem. If a first pump is used for 2.2 h and a second pump is used for 2.7 h, 1100 ft 3 can be...
-
Define the following: a. Asset b. Liability c. Net asset
-
The River City Fire Department (RCFD) fights fires and provides a variety of rescue operations in the River City metropolitan area. The RCFD staffs 13 ladder companies, 26 pumper companies, and...
-
as Suppose X is a normal variable with mean and variance 2. Let f(x) be the density function of X. For a constant 0, define the tilted density function fo(x) = f(x)ex Mo where Me is the normalization...
-
Anna Zemakis is a 49-year-old woman admitted to the hospital with severe vomiting and muscle weakness. She fell 2 weeks ago and reports not feeling well since. Four days ago, she developed abdominal...
-
For all parts of the problem, suppose the stock price today is So = $100 and suppose that at all horizons the zero rate is r = 0, Part (c) can be done independently of (a) and (b). Consider the...
-
Case A. Assume Venture Health care issued $80 million worth of $1000 par value bonds. The company's bonds have a 12%coupon rate with annual payments, and a 10-year maturity. a. What would be the...
-
Consider the prices of following American call options with different maturities and strike prices. Assume the current stock price is $30 and no dividends will be paid prior to the July expiration...
-
The market opens at 9 : 3 0 AM , at which point 1 5 , 0 0 0 shares of ABC stock trade at $ 3 5 . 6 6 a share. You decide to trade to buy 1 , 8 0 0 shares of ABC at 1 0 : 5 0 AM . The best bid and ask...
-
You need to use the formula from the Keynesian Cross Model Y=C+I+G+NX If C = cY,I = I + kY, NX = 0; c = constant; k = constant Y* = Model [Co+lo+G] (1-[c(1-T)+k]) general form using Keynesian Cross...
-
(a)What is an External Style Sheet? How to link? (b)Write CSS code that defines five classes of a paragraph with different background, color, margins, padding, and border style
-
Decades after the event, Johnson & Johnson (J&J), the 130-year-old American multinational, is still praised for swiftly The company indicated that its response was based on the expectations set forth...
-
What are the advantages and disadvantages of an instruction set architecture with variable-length instructions?
-
How are VLIW architectures similar to superscalar architectures, and how are they different? What are the relative advantages and disadvantages of each approach? In what way can VLIW architectures be...
-
Why was IEEE 754-1985 a significant development in the history of computing, especially in the fields of scientific and engineering applications?
-
Acne Medication and Gastrointestinal Injury Since 1999, Kamie Kendall had experienced ongoing abdominal pain, and she was eventually diagnosed with ulcerative colitis and irritable bowel syndrome...
-
In 1951, DuPont began using the chemical perfluorooctanoic acid to manufacture Teflon. Due to the dangerous nature of the chemical, DuPont was given special instructions by its supplier to dispose of...
-
CMS is a claims processing company in Mobile, Alabama. Chastity Jones, a black woman, completed an online employment application for a customer service position with CMS. Jones interviewed with a...
Study smarter with the SolutionInn App