Question

In: Computer Science

Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the...

Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14)

  1. Create the file PizzaOrder.java. Prompt the user to input the type of pizza that they want to order. In the end, you should print out the final order and price. Here is a sample output.

Welcome to May and Adam’s Pizzeria
Enter your first name: Amy

Pizza Size(inches)     Cost
        10            $10.99
        12            $12.99
        14            $14.99
        16            $16.99


What size pizza would you like?
10, 12, 14, or 16 (enter the number only): 12
What type of crust do you want?
  (H)Hand-tossed, (T) Thin-crust, or (D) Deep-dish (enter

   H, T, or D): H
All pizzas come with cheese.
Additional toppings are $1.25 each, choose from:
Pepperoni, Sausage, Onion, Mushroom
   Do you want Pepperoni? (Y/N): n
   Do you want Sausage? (Y/N): n
Do you want Onion? (Y/N): y
   Do you want Mushroom? (Y/N): y

Your order is as follows:
12-inch pizza
Hand-tossed crust
Cheese Onion Mushroom
The cost of your order is: $15.49
The tax is: $1.23
The total due is: $16.72
Your order will be ready for pickup in 30 minutes.

In this task you need to print out the menu, declare your variables, and assign their initial values. You will be able to make selections, but initially you will assign a hand-tossed pizza for your crust and a cost of $12.99 as a base cost for the size of your pizza.

Solutions

Expert Solution

Implementaion in JAVA:

import java.text.DecimalFormat;
import java.util.Scanner;

public class Pizzaorder {

   static Scanner s= new Scanner(System.in);
  
//   driver method
   public static void main(String[] args) {
       // TODO Auto-generated method stub

       Pizza p=new Pizza();
      
       mainmenu(p);
      
   }
  
//   main menu
   public static void mainmenu(Pizza p) {
      
       System.out.println("Welcome to May and Adam’s Pizzeria");
      
       System.out.print("Enter your first name : ");
      
       String name = s.next();
       System.out.println();
      
       System.out.println("Pizza Size(in inches) cost");
      
       System.out.println(" 10 $10.99 ");
       System.out.println(" 12 $12.99 ");
       System.out.println(" 14 $14.99 ");
       System.out.println(" 16 $16.99 ");
      
       System.out.println();
      
       System.out.println("What size pizza would you like?");
       System.out.print("10, 12, 14, or 16 (enter the number only) : ");
      
       int size=s.nextInt();
      
       switch(size) {
      
       case 10:
           double price=10.99;
           p.crust(price);
           return;
          
       case 12:
           price=12.99;
           p.crust(price);
           return;
          
       case 14:
           price=14.99;
           p.crust(price);
           return;
          
       case 16:
           price=16.99;
           p.crust(price);
           return;
          
           default:
               System.out.println("Invalid choice");
               mainmenu(p);
          
       }
      
      
      
   }

  
}

//pizza class
class Pizza{
  
   Scanner s= new Scanner(System.in);


//   will take input of crust
   public void crust(double price) {
      
       System.out.println();
       System.out.println("What type of crust do you want?");
      
       System.out.print("(H)Hand-tossed, (T) Thin-crust, or (D) Deep-dish (enter H, T, or D) : ");
      
       char crust=s.next().charAt(0);
      
//       using switch condition statement
       switch(crust) {
      
       case 'H' :
           topping_print(price,crust);
           break;
          
       case 'T' :
           topping_print(price,crust);
           break;
          
       case 'D' :
           topping_print(price,crust);
           break;
          
           default:
               System.out.println("Invalid choice");
               crust(price);
              
          
       }
      
      
      
   }
  
//   method for take input of topping nad print order
   public void topping_print(double price,char crust) {
      
       double tempp=price;
      
       System.out.println();
       System.out.println("All pizzas come with cheese.");
      
       System.out.println("Additional toppings are $1.25 each, choose from:\r\n" +
               "Pepperoni, Sausage, Onion, Mushroom");
      
       System.out.print("Do you want Pepperoni? (Y/N) : ");
       char Pepperoni =s.next().charAt(0);
      
       if(Pepperoni=='y' || Pepperoni=='Y') {
           price+=1.25;
          
       }
      
       while(Pepperoni!='y' || Pepperoni!='Y' || Pepperoni!='n' || Pepperoni!='N') {
      
      
       if(Pepperoni=='y' || Pepperoni=='Y') {
           price+=1.25;
           break;
       }
       else if(Pepperoni=='n' || Pepperoni=='N') {
           break;
       }
       else {
           System.out.println("Invalid Choice");
           System.out.print("Do you want Pepperoni? (Y/N) : ");
           Pepperoni =s.next().charAt(0);
       }
       }
      
       System.out.print("Do you want Sausage? (Y/N) : ");
       char Sausage=s.next().charAt(0);
      
       if(Sausage=='y' || Sausage=='Y') {
           price+=1.25;
          
       }
      
       while(Sausage!='y' || Sausage!='Y' || Sausage!='n' || Sausage!='N') {
      
      
       if(Sausage=='y' || Sausage=='Y') {
           price+=1.25;
           break;
       }
       else if(Sausage=='n' || Sausage=='N') {
           break;
       }
       else {
           System.out.println("Invalid Choice");
           System.out.print("Do you want Sausage? (Y/N) : ");
           Sausage =s.next().charAt(0);
       }
       }
      
       System.out.print("Do you want Onion? (Y/N) : ");
       char Onion=s.next().charAt(0);
      
       if(Onion=='y' || Onion=='Y') {
           price+=1.25;
          
       }
      
       while(Onion!='y' || Onion!='Y' || Onion!='n' || Onion!='N') {
      
      
       if(Onion=='y' || Onion=='Y') {
           price+=1.25;
           break;
       }
       else if(Onion=='n' || Onion=='N') {
           break;
       }
       else {
           System.out.println("Invalid Choice");
           System.out.print("Do you want Onion? (Y/N) : ");
           Onion =s.next().charAt(0);
       }
       }
      
      
       System.out.print("Do you want Mushroom? (Y/N) : ");
       char Mushroom=s.next().charAt(0);
      
       if(Mushroom=='y' || Mushroom=='Y') {
           price+=1.25;
          
       }
      
       while(Mushroom!='y' || Mushroom!='Y' || Mushroom!='n' || Mushroom!='N') {
      
      
       if(Mushroom=='y' || Mushroom=='Y') {
           price+=1.25;
           break;
       }
       else if(Mushroom=='n' || Mushroom=='N') {
           break;
       }
       else {
           System.out.println("Invalid Choice");
           System.out.print("Do you want Mushroom? (Y/N) : ");
           Mushroom =s.next().charAt(0);
       }
       }
      
      
//       print the order
      
       System.out.println();
      
       System.out.println("Your order is as follows : ");
      
       int size = 0;
       String type = null;
       String topping="Cheese, ";
       double tax=1.23;
      
       if(tempp==10.99)
           size=10;
      
       else if(tempp==12.99)
       size=12;
      
       else if(tempp==14.99)
           size=14;
      
       else if(tempp==16.99)
           size=16;
      
      
       if(crust=='H')
           type="Hand-tossed";
      
       else if(crust=='T')
           type="Thin-crust";
      
       else if(crust=='D')
           type="Deep-dish";
      
      
       if(Pepperoni=='Y' || Pepperoni=='y') {
           topping+="Pepperoni, ";
       }
      
       if(Sausage=='Y' || Sausage=='y') {
           topping+="Sausage, ";
       }
      
       if(Onion=='Y' || Onion=='y') {
           topping+="Onion, ";
       }
      
       if(Mushroom=='Y' || Mushroom=='y') {
           topping+="Mushroom, ";
       }
      
      
//       for upto 2 decimal format
       DecimalFormat df2 = new DecimalFormat("#.##");
      
       System.out.println(size+"-inch Pizza");
       System.out.println(type+" crust");
       System.out.println(topping);
       System.out.println("The cost of your order is : $"+df2.format(price));
       System.out.println("The tax is $"+ tax);
       System.out.println("The total Due is : $"+df2.format((price+tax)));
       System.out.println("Your order will be ready for pickup in 30 minutes.");
      
      
   }
  
  
}

SAMPLE OUTPUT:

1:

2.

If you have any doubt regarding this question please ask me in comments

// THANK YOU:-)


Related Solutions

Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
Create a Java Program to show a savings account balance. using eclipse IDE This can be...
Create a Java Program to show a savings account balance. using eclipse IDE This can be done in the main() method. Create an int variable named currentBalance and assign it the value of 0. Create an int variable named amountToSaveEachMonth. Prompt "Enter amount to save each month:" and assign the result to the int variable in step 2. Create an int variable name numberOfMonthsToSave. Prompt "Enter the number of months to save:" and store the input value into the variable...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3...
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3 Lottery. You will need to include the provided code given below in your program. Task:The program will prompt for a number between 0 and 999. Your program will display the number of attempts it took for the entered number to match a randomly generated number. In the main() method, declare an int named myPick3choice. Create a prompt for myPick3choice as "Enter your Pick 3...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious. Instructions: First create a class called Apple The class Apple DOES NOT HAVE a main method Some of the attributes of Apple are Type: A string that describes the apple.  It may only be of the following types:  Red Delicious  Golden Delicious  Gala  Granny Smith Weight: A decimal value representing...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY b. Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT