jeudi 27 août 2015

Initilaized variable in if statement, used later in code but says it isnt defined

  import java.util.Scanner;
  import java.lang.Math;

  public class pizzasMazboudi
  {
     public static void main(String[] args)
     {
    double shapeOfPizza;
    double toppings;
    double pizzaCrust;
    double baseCost;
    double areaOfPizza;
    double numberOfToppings;
    final double COST_OF_ONE_TOPPING = 0.025;
    final double COST_OF_DOUGH = 0.019;
    final double COST_OF_SAUCE = 0.036;
    double diameterOfPizza;
    double lengthOfPizza;
    double widthOfPizza;
    double volumeOfDough;
    final double THIN_AND_CRISPY = .1;
    final double PAN = .5;
    final double CLASSIC_HAND_TOSSED = .25;
    final double TEXAS_TOAST = .9;
    double sizeOfCrust;
    double cheesyCrust;
    final double COST_OF_MATERIALS = .02;
    double numberOfPizzas;
    double costOfDelivery;
    double tax;
    double pizzaDelivery;
    final double PI = 3.14159;
    double typeOfCrust;
  double costOfCheesyCrust;
    double costOfPizzaDelivery;

  Scanner keyboard = new Scanner(System.in);
  System.out.println("Hello customer! Welcome to Guiseppi's Just Pizza!");
  System.out.println("Where we make the pizza just for you!");
  System.out.println("\n What kind of pizza do you want on" + 
                     " this beautiful day?");
  do
     {
     System.out.print("Press 1 for a square pizza,");  
     System.out.print(" or press 2 for a circle pizza: ");
     shapeOfPizza = keyboard.nextDouble();

        if(shapeOfPizza != 1 && shapeOfPizza != 2)
           {
           System.out.println("That is an incorrect input, please enter 1 or 2");
           }
      }  
  while(shapeOfPizza != 1 && shapeOfPizza != 2);

  if(shapeOfPizza == 1)
     {
     System.out.println("And how big would you like your pizza?");

        do
           {
           System.out.print("Please enter the length of your pizza (under 60 inches: ");
           lengthOfPizza = keyboard.nextDouble();

              if(lengthOfPizza > 60 && lengthOfPizza < 0)
                 {
                 System.out.println("That is an incorrect input, please enter a number between 0 and 60");
                 }
           }
        while(lengthOfPizza > 60 && lengthOfPizza < 0);

        do
           {   
           System.out.print("Please enter the width of your pizza: ");
           widthOfPizza = keyboard.nextDouble();

              if(widthOfPizza >60 && widthOfPizza <0)
                 {
                 System.out.println("That is an incorrect input, please enter a number between 0 and 60.");
                 }
           }
        while(widthOfPizza > 60 && widthOfPizza < 0);

        areaOfPizza = lengthOfPizza * widthOfPizza;
        System.out.println("Your pizza is " + areaOfPizza + "inches large");
        sizeOfCrust = 2 * (lengthOfPizza + widthOfPizza);
     }   

  else if(shapeOfPizza == 2)
     {
     System.out.println("And how big would you like your pizza?");
     do
        {
        System.out.print("Please enter the diameter of your pizza: ");
        diameterOfPizza = keyboard.nextDouble();
           if(diameterOfPizza > 60 && diameterOfPizza <= 0)
              {
              System.out.println("That is an incorrect input, please enter a number that is between 0 and 60.");
              }
        }
     while(diameterOfPizza > 60 && diameterOfPizza <= 0);

        sizeOfCrust = 2*PI*(diameterOfPizza/2);
        areaOfPizza = PI*((diameterOfPizza/2)*(diameterOfPizza/2));
        System.out.println("The area of your pizza is" + areaOfPizza + " inches large");
     }

  System.out.println("What type of crust would you like?");
  do
     {
     System.out.println("Enter 1 for Thin and Crispy, 2 for Pan,"); 
     System.out.println("3 for Classic Hand-Tossed, and 4 for Texas Toast");
     pizzaCrust = keyboard.nextDouble();
        if(pizzaCrust != 2 && pizzaCrust != 3 && pizzaCrust != 4)
           {
           System.out.println("That is an incorrect input, please enter 1, 2, 3, or 4");
           }
     }
  while(pizzaCrust != 2 && pizzaCrust != 3 && pizzaCrust != 4);

  if(pizzaCrust == 1);
     {
     typeOfCrust = THIN_AND_CRISPY;
     }
  if(pizzaCrust == 2);
     {
     typeOfCrust = PAN;
     }
  if(pizzaCrust == 3);
     {
     typeOfCrust = CLASSIC_HAND_TOSSED;
     }
  if(pizzaCrust == 4);
     {
     typeOfCrust = TEXAS_TOAST;
     }

  if(pizzaCrust == 2 && pizzaCrust == 3 && pizzaCrust == 4)
     {
     System.out.println("Would you like to try our new cheesy crust today?");
     do
        {
        System.out.print("Enter 1 for yes or 2 for no");
        cheesyCrust = keyboard.nextDouble();
           if(cheesyCrust != 1 && cheesyCrust != 2)
              {
              System.out.println("That is an incorrect input, please enter 1 or 2");
              }
        }
     while(cheesyCrust != 1 && cheesyCrust != 2);
     }
  System.out.println("Would you like any toppings today?");
  do
     {
     System.out.println("Enter 1 for toppings, enter 2 if you do not want toppings");
     toppings = keyboard.nextDouble(); 
        if(toppings != 1 && toppings !=2)
           {
           System.out.println("That is an incorrect input, please enter 1 or 2");
           }
     }
  while(toppings != 1 && toppings !=2);

  if(toppings == 1)
     {
        do
           {
           System.out.println("How many toppings do you want? (10 toppings limit)");
           numberOfToppings = keyboard.nextDouble();
              if(numberOfToppings <=0 && numberOfToppings > 10)
                 {
                 System.out.println("That is an incorrect input, please enter a number 1 through ten");
                 }
           }
        while(numberOfToppings <=0 && numberOfToppings > 10);
     }

  do
     {
     System.out.println("How many identical pizza's would you like?");
     numberOfPizzas = keyboard.nextDouble();
        if(numberOfPizzas <= 0)
           {
           System.out.println("That is an incorrect input, please enter a number above 0");
           }
     }
  while(numberOfPizzas <= 0);

  System.out.println("Will you come pick up your order, or will you like delivery?");
  do
     {
     System.out.println("Enter 1 for delivery, enter 2 for pick-up");
     pizzaDelivery = keyboard.nextInt();
        if(pizzaDelivery != 1 && pizzaDelivery != 2)
           {
           System.out.println("That is an incorrect input, please enter a 1 or 2");
           }
     }
  while(pizzaDelivery != 1 && pizzaDelivery != 2);

  costOfCheesyCrust = sizeOfCrust * COST_OF_MATERIALS;
  volumeOfDough = typeOfCrust * areaOfPizza;
  baseCost = areaOfPizza * (COST_OF_SAUCE + numberOfToppings * COST_OF_ONE_TOPPING) + COST_OF_DOUGH * volumeOfDough;

  if(cheesyCrust == 1)
     {
     costOfCheesyCrust = sizeOfCrust * COST_OF_MATERIALS;
     baseCost = baseCost + costOfCheesyCrust;
     }
  if(pizzaDelivery == 1)
     {
     if(baseCost < 10)
        {
        costOfPizzaDelivery = 3.00;
        }
     else if(baseCost < 20 || baseCost >= 10)
        {
        costOfPizzaDelivery = 2.00;
        }
     else if(baseCost < 30 || baseCost >= 20)
        {
        costOfPizzaDelivery = 1.00;
        }
     else if(baseCost >= 30)
        {
        costOfPizzaDelivery = 0;
        }
     }
 }

}

So when i try to compile this, the variables numberOfTopping, areaOfPizza, and sizeOfCrust are all causes of errors because "they aren't initialized", but i have have defined them all as doubles and set numberOfTopping as keyboard.nextDouble and given the other 2 formulas, any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire