Answer:
Here is the JAVA program:
import java.util.Scanner; //to accept input from user
public class FunWithBranching { //class name
public static void main(String[] args) { //start of main function
Scanner input = new Scanner(System.in); //creates Scanner object
System.out.print("Enter your name: "); //prompts user to enter name
String userName = input.nextLine(); //stores the name
System.out.print("Welcome " + userName + "! Please answer the following questions:\n"); //prompts user to answer the questions
int randomOperand1 = (int)(20 * Math.random()) + 1; //generates random number for operand 1 (1-20)
int randomOperand2 = (int)(20 * Math.random()) + 1; //generates random number for operand 2 (1-20)
int randomAdd = randomOperand1 + randomOperand2; //performs addition of two random numbers and stores result in randomAdd
int randomMul = randomOperand1 * randomOperand2; //performs multiplication of two random numbers
int randomDiv = randomOperand1 / randomOperand2; //performs division of two random numbers
int randomMod = randomOperand1 % randomOperand2; //performs modulo of two random numbers
int correctAns = 0; //stores number of correct answers
System.out.print(randomOperand1 + " + " + randomOperand2 + " = "); //displays random number + random number
int AdditionGuess = input.nextInt(); //reads the answer of addition from user and stores it in AdditionGuess
if (AdditionGuess == randomOperand1 + randomOperand2) { //if the user answer is correct
System.out.println("Correct!"); //displays correct
correctAns++; //adds 1 to the count of correctAns every time the user gives correct answer of addition
} else { //if user answer is incorrect
System.out.println("Wrong!"); //displays wrong
System.out.println("The correct answer is " + randomAdd); } //displays the correct answer of addition
System.out.print(randomOperand1 + " * " + randomOperand2 + " = "); //displays random number * random number
int MultiplicationGuess = input.nextInt(); //reads the answer of multiplication from user and stores it in MultiplicationGuess
if (MultiplicationGuess == randomOperand1 * randomOperand2) { //if the user answer is correct
System.out.println("Correct!"); //displays correct
correctAns++; //adds 1 to the count of correctAns every time the user gives correct answer of multiplication
}else{ //if user answer is incorrect
System.out.println("Wrong!"); //displays wrong
System.out.println("The correct answer is " + randomMul); } //displays the correct answer of multiplication
System.out.print(randomOperand1 + " / " + randomOperand2 + " = "); //displays random number / random number
int DivisionGuess = input.nextInt(); //reads the answer of division from user and stores it in DivisionGuess
if (DivisionGuess == randomOperand1 / randomOperand2) { //if the user answer is correct
System.out.println("Correct!"); //displays correct
correctAns++; //adds 1 to the count of correctAns every time the user gives correct answer of division
}else{ //if user answer is incorrect
System.out.println("Wrong!"); //displays wrong
System.out.println("The correct answer is " + randomDiv); } //displays the correct answer of division
System.out.print(randomOperand1 + " % " + randomOperand2 + " = "); //displays random number % random number
int ModGuess = input.nextInt(); //reads the answer of modulo from user and stores it in ModGuess
if (ModGuess == randomOperand1 % randomOperand2) { //if the user answer is correct
System.out.println("Correct!"); //displays correct
correctAns++; //adds 1 to the count of correctAns every time the user gives correct answer of modulo
}else{ //if user answer is incorrect
System.out.println("Wrong!"); //displays wrong
System.out.println("The correct answer is " + randomMod); } //displays the correct answer of modulo
double percentage = correctAns * 25; //computes percentage
System.out.println("You got " + correctAns + " correct answers."); //display number of correct answers given by user
System.out.println("That's " + percentage + "%!"); } } //displays percentage
Explanation:
The program is well explained in the comments mentioned with each line of code. The screenshot of the output is attached.