我一直在和这个人争吵很长一段时间,但是我把所有的错误都拿掉了,但我似乎无法理解最后两个错误出现的原因。
以下是错误:
我一直得到这些:
java:101:错误:虽然预期 }
java:102:错误:解析时到达文件末尾 }
{
BufferedReader bReader = new BufferedReader (new InputStreamReader (System.in));
String people;
int tickets; // here we start setting all the variables
char ticketloop;
double price;
String movie, surname;
price = 20.00;
tickets = 0;
Scanner sc = new Scanner(System.in);
{
System.out.println("Please enter surname of patron: ");
Scanner surnameScan = new Scanner(System.in);
surname = surnameScan.nextLine();
}
{
System.out.println("Please enter name of the show: ");
Scanner movieScan = new Scanner(System.in);
movie = movieScan.nextLine();
}
{
System.out.println("Please enter number of people: ");
int x= Integer; parseInt (people); //converting people string into an integer
people = bReader.readLine();
}
{
while(people <0 || people >10)
{
System.out.println("Wait, way to many people!"); // I just use this in case th euser puts more than 10 users
Scanner peopleScan = new Scanner(System.in);
people = peopleScan.nextLine(); // User Input
}
tickets = tickets + 1; // Adds 1 to counter
if(people >6)
price=20.00-(20.00/100)*10; // Uses discount price if there are more than 6 people
else
price=20.00; // If less than 6, then does not use the discount
System.out.println("Movie : " +movie); // Prints show name entered by user on the screen
System.out.println("Surname : " +surname); // Prints the surname entered by user on the screen
System.out.println("How many are you: " +people); // Prints the number of people entered by user on the screen
if(people >6) // If statement
System.out.println("Final Price: " +price*people); // If number of people is bigger than 6 it prints out 10% DISCOUNT message and calculates total cost
else // Else statement
System.out.println("Final Price : " +price*people); // If number of people is less than 6 calculates total cost and prints the result on the screen
System.out.println("Want more tickets? Enter 'y' / 'n' and press <enter>"); // Prompts user for input
System.out.println("---------------------------------------------------------");
Scanner ticketloopScan = new Scanner(System.in);
Char ticketloop = ticketloopScan.nextLine(); // User input
while(ticketloop !='y' && ticketloop !='n') // While loop to determine if the user entered a value outside the given options
{
System.out.println("That's not right! Enter y or n"); // Prints this if user enters an invalid input
Scanner ticketloopScan = new Scanner(System.in);
String ticketloop = ticketoopScan.nextLine(); // User input
}
while(ticketloop =='y'); // do/while structure
if(ticketloop =='n') // If comparison operator
System.out.println("Total number of tickets processed: " + tickets); // Prints out number of total tickets processed before quitting
System.out.println("Have a nice day! "
}
}
}
答案 0 :(得分:0)
String movie, surname;{
这里做的花括号是什么?删除它。
答案 1 :(得分:0)
我已经改变了我的代码大部分时间,仍然有一些错误,但它运行了。
BufferedReader bReader = new BufferedReader (new InputStreamReader (System.in));
Scanner sc = new Scanner(System.in);
int people, tickets; // here we start setting all the variables
double price;
String movie, surname;
price = 20.00;
tickets = 0;
{
Scanner sc1 = new Scanner(System.in);
System.out.println("Please enter surname of patron: ");
surname = sc1.nextLine ();
}
{
Scanner sc2 = new Scanner(System.in);
System.out.println("Please enter name of the movie: ");
movie = sc2.nextLine ();
}
{
Scanner sc3 = new Scanner(System.in);
System.out.println("Please enter number of people: ");
people = sc3.nextInt ();
}
{
while(people <0 || people >10)
{
System.out.println("Wait, way to many people!"); // I just use this in case th euser puts more than 10 users
Scanner sc4 = new Scanner(System.in);
people = sc4.nextInt(); // User Input
}
tickets = tickets + 1; // Adds 1 to counter
if(people >6)
price=20.00-(20.00/100)*10; // Uses discount price if there are more than 6 people
else
price=20.00; // If less than 6, then does not use the discount
System.out.println("Movie : " +movie); // Prints show name entered by user on the screen
System.out.println("Surname : " +surname); // Prints the surname entered by user on the screen
System.out.println("How many are you: " +people); // Prints the number of people entered by user on the screen
if(people >6) // If statement
System.out.println("Final Price: " +price*people); // If number of people is bigger than 6 it prints out 10% DISCOUNT message and calculates total cost
else // Else statement
System.out.println("Final Price : " +price*people); // If number of people is less than 6 calculates total cost and prints the result on the screen
System.out.println("Want more tickets? Enter 'y' / 'n' and press <enter>"); // Prompts user for input
System.out.println("---------------------------------------------------------");
Scanner sc5 = new Scanner(System.in);
char ticketloop;
ticketloop = sc5.next().charAt(0); // User input
while(ticketloop !='y' && ticketloop !='n') // While loop to determine if the user entered a value outside the given options
{
System.out.println("That's not right! Enter y or n"); // Prints this if user enters an invalid input
Scanner sc6 = new Scanner(System.in);
char yesorno;
yesorno = sc6.next().charAt(0);
// User input
}
while(ticketloop =='y'); // do/while structure
if(ticketloop =='n') // If comparison operator
System.out.println("Total number of tickets processed: " + tickets); // Prints out number of total tickets processed before quitting
System.out.println("Have a nice day! ");
}
}
}