I am so very lost I truly believe that this code should be working but i am getting errors that i can’t seem to fix.
public class MainActivity {
// Add generateRandomNumber() here
public int generateRandomNumber(int max){
double value = Math.random() * max;
double number = (double) value;
int result = (int) number;
return result;
// Add getGameOverMessage() here
public String getGameOverMessage(int totalCorrect, int totalQuestions) {
if (totalCorrect == totalQuestions) {
return “You got all " + totalQuestions + " right! You won!”;
} else {
return "You got " + totalCorrect + " right out of " + totalQuestions + “. Better luck next time!”;
}
}
}
Have I missed something obvious? I am trying to get this getGameOver message statement to display properly, but this is the error i am getting:
MainActivity.java:11: error: illegal start of expression
public String getGameOverMessage(int totalCorrect, int totalQuestions) {
^
1 error
public int generateRandomNumber(int max){
double value = Math.random() * max;
double number = (double) value;
int result = (int) number;
return result;
The function has not been closed. As a general rule, one cannot declare a function inside another function.
For example:
public int someFunc() {
public string anotherFunc(){
//code
return "Hello!";
}
return 5;
}
Cannot be done, but:
public int someFunc(){
//code
return 5;
}
public string anotherFunc(){
//code
return "Hello!";
}