The code below all works as it should except the if(choice = “1”). The program just stops working when I input for soloParty or multiParty in the console.
import java.util.Scanner;
public class OrderApp {
//make sure to add menu and choose between a big group and solo group
public void main(String[] args) {
double burger; //number of burgers ordered
double fries; //number of fries ordered
double soda; // number of soda ordered
double groupNumber;
Scanner input = new Scanner(System.in);
//add menu
System.out.println("Menu");
System.out.println("----------------");
System.out.println("1 - Solo party");
System.out.println("2 - Multiple Party");
System.out.print("--->");
int choice = input.nextInt();
input.nextLine();
//conditional
if (choice = "1") {
//Solo party
System.out.print("Enter the amount of burgers>>>:");
burger = input.nextInt();
} else {
//multip party
System.out.print("Enter Amount of Party Members");
groupNumber = input.nextInt();
}
}
}
Its specfically the if(choice = "1")
and the }else{ it has a red line under it in VScode. I have no idea to how have the users input assign to an int and then have it run a different block of code depending on the input. I just need to know how to have the users input decide which code block to run.
Aidan Maness is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
you reminded me when i was first introduced to programming. first, if this is the main class to run your program , you missed out the word ‘static’ in your main class.
intead of
public void main(String[] args) {
you should write
public static void main(String[] args) {
second, comparison is double equal sign.
third, you should use 1 instead of “1” because the datatype of your choice is int.
so you should use
if(choice == 1){
say hello to java world. cheers
1