[JAVA] assignment help
Go to solution
Solved by martward,
3 minutes ago, huracan said:
so i did manage to declare the string at the beginning but im getting a different kind of error.
Sandwich.java:39: error: variable sammichPrice might not have been initialized System.out.println("you have odered a" + sammichSize + sammichType + "sandwich. youre total is: " + sammichPrice );Heres how i declared it
String sammichType =new String() ; String sammichSize = new String();
Yes so you have if ... else if statements, but no else. This means that in theory the values may not be initialized, for instance when the user enters "5" somewhere.
So either you should give the sammichType and sammischSize a default value (String sammichType =new String("Turkey Pesto"); ) or you replace the last else ifs for else's.
That way the variable is always initialized.
Alternatively you could make a while loop that loops until the user enters a value that actually represents something in the menu.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now