Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java . I am new to Java and experiencing some difficulty getting my latest program to compile. I will save the problem definition, as it

Java. I am new to Java and experiencing some difficulty getting my latest program to compile. I will save the problem definition, as it is not necessary in this case. I have followed the textbook solution for this problem perfectly, but for some reason it is not liking a few lines. I thought perhaps my braces were off, but I double-checked them and they seem correct. I really feel like it should compile, but it is not liking the "generateQuestion()" function call inside the while(true) body, it is saying "Cannot resolve method generateQuestion()". It also doesn't like the "generateQuesion()" function definition on the next line, it is saying "; expected, Expected Expression". It doesn't like the mathProblem(x, y) function call as the argument in the if statement, it says "Cannot resolve method mathProblem(int, int)", and finally, it doesn't like the function definition for "public static boolean mathProblem(int x, int y), it's giving me the same error as the generateQuestion(), "; expected, Expected Expression". Oh and it doesn't like the return true or return false in the body, it is saying "Cannot return a value from a method with void result type". It's funny, because it looks to me that I have it set to return a boolean value, especially when it says boolean in the function header. Please help me, I am using IntelliJ IDEA 2019. Here is the actual code:

import java.util.Scanner; // Allow Input from the User import java.security.SecureRandom; // Nondeterministic Random Number Class public class Computer_Assisted_Instruction // Name of the Java File Automatically Becomes the Name of the Primary { public static void main(String[] args) // Java's Method of Declaring the Driver Function (int main) { Scanner input = new Scanner(System.in); // Input from the User while(true) // Main Game Loop... Continue to Execute Until a False Condition is Reached { generateQuestion(); // "generateQuestion" Function Call } public static void generateQuestion() { boolean again = false; // Again Declared as a Boolean Value and Initialized to False SecureRandom randomNumbers = new SecureRandom(); // Random Numbers Declared as the Parameter for the int x = randomNumbers.nextInt(10) + 1; // Generate Value Between Zero and Nine, Add One to Get 1-9 int y = randomNumbers.nextInt(10) + 1; // Generate Value Between Zero and Nine, Add One to Get 1-9 while(!again) // If Again is Set to True... { int response; // Response Declared as an Integer Datatype if(mathProblem(x, y)) { response = randomNumbers.nextInt(4); // Generate Value Between Zero and Four switch(response) { case 0: System.out.println("Very Good!"); // Display "Very Good" Response to Correct Answer break; case 1: System.out.println("Excellent!"); // Display "Excellent" Response to Correct Answer break; case 2: System.out.println("Nice Work!"); // Display "Nice Work" Response to Correct Answer break; case 3: System.out.println("Keep Up the Good Work!"); // Display "Keep Up the Good Work" break; } again = true; // This Is Where the Loop Sets Again Equal to True } else { response = randomNumbers.nextInt(4); // Generate Value Between Zero and Four switch(response) { case 0: System.out.println("No. Please Try Again."); // Display "No. Please Try Again." break; case 1: System.out.println("Wrong. Try Once More."); // Display "Wrong. Try Once More." break; case 2: System.out.println("Don't Give Up!"); // Display "Don't Give Up!" Response to break; case 3: System.out.println("No. Keep Trying!"); // Display "No. Keep Trying!" Response to break; } } } } public static boolean mathProblem(int x, int y) { int answer; // User's Answer Declared as an Integer Datatype System.out.print("How Much Is " + x + " Times " + y + "?"); answer = input.nextInt(); // User Inputs Their Answer if(answer == x * y) return true; else return false; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

=+1 What would you do if you were the IHR manager?

Answered: 1 week ago