-2

I tried to convert it to char but I'm still getting a problem that it won't build properly, newbie here. But any help would do please

import java.util.Scanner;

public class PizzaChoice {

    public static void main(String[] args){
        //char sizes;
        Scanner input = new Scanner(System.in);
        final int NUMBER_OF_CHOICES = 4;
        char[] pizzaSize = {'S', 'M', 'L', 'X'};
        double[] prices = {6.99, 8.99, 12.50, 15.00};
        char sizeChosen;
        double pizzaPrice = 0.0;
        boolean validChoice = false;
        Scanner inputDevice = new Scanner(System.in);
        System.out.print("Enter pizza size- S, M, L, or X: ");
        sizeChosen = inputDevice.nextLine().charAt(0);
        for(int s = 0; s < NUMBER_OF_CHOICES; ++s)
        {      
            if(sizeChosen.equals(pizzaSize[s]))
            {  
                validChoice = true;
                pizzaPrice = prices[s];
            }
        }
        if(validChoice)
            System.out.println("The price for chosen size " +
                    sizeChosen + " is $" + pizzaPrice);
        else
            System.out.println("Sorry - Invalid Choice Entered");  

    }

}
L. Swifter
  • 3,179
  • 28
  • 52

1 Answers1

0

Replace char for pizzaSize and sizeChosen by Character and it will work. See "Char cannot be dereferenced" error

Community
  • 1
  • 1
  • Thank you also!! :) – Danny Black Nov 19 '16 at 14:08
  • @DannyBlack You shouldn't really do that. Patrick just made a joke, I hope. Avoid unnecessary boxing and just compare your `char` correctly (Berger told you how to do that). – Tom Nov 20 '16 at 19:04
  • I don't really see why you shouldn't do that. It works like a charm. But I'm not an expert, just trying to help out, so please explain what's wrong with that solution. – Patrick van Deudekom Nov 21 '16 at 13:18