Working on a hw assignment and I am getting this following error. Please help me understand what is occurring. Thank you!
Sandwich.java:5: error: illegal start of expression
public String MainIngredient;
^
Sandwich.java:6: error: illegal start of expression
public String Bread;
^
Sandwich.java:7: error: illegal start of expression
public double Price;}
^
3 errors
Error: Could not find or load main class Sandwich
Reminder: this is a C++ forum. Java questions are best taken to a Java forum, and are off-topic here.
That said, the issue you're dealing with is pretty universal: you're declaring your fields inside main(). Try moving lines 5 to 7 (excluding the closing brace) outside of main() and your issue should clear right up.
not a java expert (you have come to a forum for a totally different language. Its like asking the French language experts to help you do your Russian homework).
But it looks to me like the private members of the class should not be in the function, but outside it up in the class level scope. That is it looks like you have mangled the class and the main method together, and they should be more distinct. Why the heck main is inside a class anyway... freakin java...