Reputation: 13
I try to figure out which line I miss the "{". it tells me in the 3rd line I expected to put "{" symbol and I did but still gives me an error. this is my code:
package lab22;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner Sc = new Scanner(System.in);
int choice = 0;
int coffee = 0;
int tea = 0;
int coke = 0;
int orange = 0;
int pnum = 1;
System.out.println("Baverage:\n1. Coffee\n2. Tea\n3. Coke\n4. Orange Juice");
do{
System.out.println("Please input the favourite beverage of person #"+ String.valueOf(pnum)+": Choose 1, 2, 3, or 4 from the above menu or -1 to exit");
choice = Sc.nextInt();
if (choice == 1){
coffee += 1;
} else if (choice == 2){
tea += 1;
} else if (choice == 3){
coke += 1;
} else if (choice == 4){
orange += 1;
} else if (choice != -1){
System.out.println("Please enter valid input!");
continue;
}
pnum += 1;
} while(choice != -1);
System.out.println(" Beverage Number of Votes");
System.out.println(" *************************");
System.out.println("Coffee: "+ String.valueOf(coffee));
System.out.println("Tea: "+ String.valueOf(tea));
System.out.println("Coke: "+ String.valueOf(coke));
System.out.println("Orange Jiuce: "+ String.valueOf(coffee));
}
}
can someone help what did i miss?
Upvotes: 0
Views: 122
Reputation: 4582
Before starting your code you need to first understand basic naming conventions in Java.
As far as error concern you need to remove that .java
from class name to get rid of the error.
Additionally:
a) Class name should start with Capital Letter (CamelCase).
b) Variable name should start with Small Letter (CamelCase).
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int choice = 0;
int coffee = 0;
int tea = 0;
int coke = 0;
int orange = 0;
int pnum = 1;
System.out.println("Baverage:\n1. Coffee\n2. Tea\n3. Coke\n4. Orange Juice");
do {
System.out.println("Please input the favourite beverage of person #" + String.valueOf(pnum)
+ ": Choose 1, 2, 3, or 4 from the above menu or -1 to exit");
choice = sc.nextInt();
if (choice == 1) {
coffee += 1;
} else if (choice == 2) {
tea += 1;
} else if (choice == 3) {
coke += 1;
} else if (choice == 4) {
orange += 1;
} else if (choice != -1) {
System.out.println("Please enter valid input!");
continue;
}
pnum += 1;
} while (choice != -1);
System.out.println(" Beverage Number of Votes");
System.out.println(" *************************");
System.out.println("Coffee: " + String.valueOf(coffee));
System.out.println("Tea: " + String.valueOf(tea));
System.out.println("Coke: " + String.valueOf(coke));
System.out.println("Orange Jiuce: " + String.valueOf(coffee));
}
}
As I have changed the class name, probably you would need to rename your file also containing the class as Main.java
.
Upvotes: 1