Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: I don't understand why I get assigned value never used. line 32,33,93

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I don't understand why I get assigned value never used. line 32,33,93

    //
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     * This program allows the user to order a pizza
     *
     * @author Juan Carlos sanabria
     */
     
    import java.util.Scanner; 
     import java.text.DecimalFormat;
     
     
    public class PizzaOrder 
    {
       public static void main (String [] args)
       {
           //TASK #5 Create a DecimalFormat object with 2 decimal places
           // You have to add code!!!
            DecimalFormat DollarFormat = new DecimalFormat("#0.00");
     
           //Create a Scanner object to read input 
           Scanner keyboard = new Scanner (System.in); 
     
           String firstName;            //user's first name 
           boolean discount = false;    //flag, true if user is eligible for discount 
           int inches;                  //size of the pizza 
           char crustType;              //code for type of crust******* 
           String crust = null;                //name of crust 
           double cost = 12.99;                 //cost of pizza******
           final double TAX_RATE = .08; //sales tax rate 
           double tax;                  //amount of tax 
           char choice;                 //user's choice 
           String input;                //user input 
           String toppings= ("With these Toppings\n");                     
           int numberOfToppings=0;        //number of toppings*********
     
           //prompt user and get first name 
           System.out.println("Welcome to Mike and Diane's Pizza\n"); 
           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 
           if(firstName.compareToIgnoreCase("Mike")==0|| firstName.compareToIgnoreCase("Diane")==0)
          discount=true;     
     
     
           //prompt user and get pizza size choice 
           System.out.println("\nPizza Size (inches) Cost\n"); 
           System.out.println(" 10 $10.99"); 
           System.out.println(" 12 $12.99"); 
           System.out.println(" 14 $14.99"); 
           System.out.println(" 16 $16.99\n"); 
           System.out.println("What size pizza would you like?"); 
           System.out.print("10, 12, 14, or 16 (enter the number only):\n "); 
           inches = keyboard.nextInt(); 
     
     //set price and size of pizza ordered 
           if(inches==10)
         cost=10.99;
            else if(inches==12)
         cost=12.99;
            else if(inches==14)
         cost=14.99;
            else if(inches==16)
         cost=16.99;
            else
            {System.out.println(inches+" is not a valid size-you will recieve a 12\" pizza");
                inches=12;
                cost=12.99;
            }
                System.out.println("The size of your pizza is" + " " + inches+" inches");
                System.out.println("The cost of your pizza is" + " " + cost);
     
     //ADD LINES HERE FOR TASK #2 
     
     //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, (T) Thin-crust, or " + 
           "(D) Deep-dish (enter H, T, or D): "); 
           input = keyboard.nextLine(); 
           crustType = input.charAt(0);
           choice=crustType;
     
     
           //set user's crust choice on pizza ordered 
     
           //ADD LINES FOR TASK #3....sWITCH sTATEMENT
           switch(crustType)
           {default: System.out.println(crustType+" is not a choice-you will get Hand-tossed");
              //crustType='h';
           case 'H':
           case 'h': crust="Hand-tossed";
               break;
           case 'T':
           case 't': crust="Thin-crust";
               break;
           case 'D':
           case 'd': crust="Deep-dish ";
               break;
     
            }  
           System.out.println("You ordered a"+" "+crust+" "+"pizza\n");
     
         //prompt user and get topping choices one at a time
            System.out.println("All pizzas come with cheese.\n");
            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') 
         { 
            numberOfToppings += 1; 
            toppings = toppings + "Pepperoni "; 
     } 
            System.out.print("Do you want Sausage? (Y/N): "); 
            input = keyboard.nextLine(); 
            choice = input.charAt(0); 
            if (choice == 'Y' || choice == 'y') 
     { 
            numberOfToppings += 1; 
            toppings = toppings + "Sausage "; 
     } 
            System.out.print("Do you want Onion? (Y/N): "); 
            input = keyboard.nextLine(); 
            choice = input.charAt(0); 
            if (choice == 'Y' || choice == '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 elible
            //ADD LINES FOR TASK #4 HERE
    if(discount)
        {System.out.println("You are eligible for a $2 discount");
        cost-=2;
        }
            //EDIT PROGRAM FOR TASK #5
     
            //SO ALL MONEY OUTPUT APPEARS WITH 2 DECIMAL PLACES
    System.out.println("The cost of your order is: $" +DollarFormat.format(cost));
     
    //calculate and display tax and total cost
     
    tax = cost * TAX_RATE;
     
    System.out.println("The tax is: $" + DollarFormat.format(tax));
     
    System.out.println("The total due is: $" + DollarFormat.format(tax+cost));
     
    System.out.println("Your order will be ready for pickup in 30 minutes.");
     
     
     
       }
    }
    //


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,382
    Thanks
    53
    Thanked 2,398 Times in 2,351 Posts

    Default Re: I don't understand why I get assigned value never used. line 32,33,93

    Please post the full text of the error messages that show the statements where the errors are.
    Or add comments like: //*** Here is the error
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. I don't understand this. Please help...
    By javaman1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 20th, 2014, 04:32 AM
  2. I don't understand what's wrong in my programme
    By si3012 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 16th, 2013, 07:58 AM
  3. Don't understand void methods, need help!
    By alex067 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 9th, 2012, 07:02 AM
  4. Simply don't understand minimax...
    By Herah in forum Algorithms & Recursion
    Replies: 3
    Last Post: October 13th, 2011, 12:45 PM
  5. I don't understand what I'm supposed to do
    By dmcettrick in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 11th, 2011, 09:34 AM