This question already has an answer here:
- How do I compare strings in Java? 23 answers
public class Pizza {
public static void main(String[] args)
{
// Greeting to the pizza shop.
System.out.println("Welcome to Adam's Pizza Shop.");
System.out.println();
// Asking the user for their name and scanner utility for input.
Scanner scan;
scan = new Scanner(System.in);
System.out.print("What is your name? ");
String name = scan.next();
System.out.println("Welcome " + name);
System.out.println();
// Prompt the user to choose between three types of pizza.
System.out.println("These are the three types of pizza we sell here at Adam's Pizza Shop:");
System.out.println("Cheese--------" + "C");
System.out.println("Margherita----" + "M");
System.out.println("Sausage-------" + "S");
System.out.println();
// Asking what kind of pizza the customer wants
System.out.println("Type the letter for the type of pizza you want: ");
Scanner scan2;
scan2 = new Scanner(System.in);
String userChoice = scan2.next();
// If statements for when the customer selects the type of pizza they would like
if (userChoice == "C") {
System.out.println("12 inch $9.50");
System.out.println("16 inch $13.50");
}
if (userChoice == "M") {
System.out.println("12 inch $11.50");
System.out.println("16 inch $15.50");
}
if (userChoice == "S") {
System.out.println("12 inch $12.50");
System.out.println("16 inch $16.50");
}
else {
System.out.println("Not a valid selection, goodbye " + name + "!");
}
}
}
//Whenever I put in an option for what style of pizza I get the same not valid selection from my //else loop. I need a code where I will select cheese pizza and then that user input will take me to //the size and price of the pizza.
Aucun commentaire:
Enregistrer un commentaire