Question

In: Computer Science

Write a program for multiplication quiz. It displays to the student a question such as “What...

Write a program for multiplication quiz.

It displays to the student a question such as “What is 5 × 19?”. After the student enters the answer, the program displays a message indicating whether it is correct.

Note: you can use Math.random() to obtain a random integer value between 0 and 100.

JAVA

Solutions

Expert Solution

//MathQuiz.java

import java.util.Random;
import java.util.Scanner;

public class MathQuiz {
    public static void main(String[] args) {
        System.out.println("Welcome to multiplication quiz!\n\n");
        // random for generating random number
        Random rand = new Random();
        Scanner scanner = new Scanner(System.in);
        int num1, num2;
        while (true) {
            // generating random number between 0 and 100 
            num1 = rand.nextInt(99) + 1;
            num2 = rand.nextInt(99) + 2;
            System.out.println(String.format("What is %d × %d?", num1, num2));
            // scanning the user answer
            int userAnswer = scanner.nextInt();
            // computing the correct answer
            int correctAnswer = num1 * num2;
            // comparing the answer and printing result accordingly
            if (userAnswer == correctAnswer) {
                System.out.println("Correct Answer");
            }
            else System.out.println("Sorry! Incorrect Answer, Correct Answer is : "+correctAnswer);
            // asking if want to play again
            System.out.print("Do you continue want to play[y/n]? ");
            String choice = scanner.next().toLowerCase().trim();
            if(choice.charAt(0)=='n'){
                System.out.println("Thanks for Playing!!!");
                break;
            }
            System.out.println();
        }
    }
}

//OUTPUT

Please do let me know if u have any concern...


Related Solutions

For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
OverviewFor this assignment, write a program that will calculate the quiz average for a student in...
OverviewFor this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array.For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores).It is recommended that this program be written in two versions. The first version of the program will read a set of quiz scores from...
java programming question: "Write a program that displays a page on a topic of interest to...
java programming question: "Write a program that displays a page on a topic of interest to you (e.g., a sport, a city). Include at least one image and one shape (which can be text). " I wanted to do a soccer page but I don't know how to put pictures from the internet on Java. As for my object, I wanted to make a soccer ball. My professor has been really confusing in explaining graphics so any help is appreciated!
write a “quiz” program on a topic, about which you are knowledgeable. this quiz can be...
write a “quiz” program on a topic, about which you are knowledgeable. this quiz can be work related, general knowledge or any set of questions where there is a specific answer. ignore questions where long descriptions or general answers needed. the program should display the questions, one at a time, and possible answers, and accept an answer from the user. if the answer is correct, the program should go on to the next question. if it is incorrect, store the...
Design and write a Python 3.8 program that gives and grades a math quiz. The quiz...
Design and write a Python 3.8 program that gives and grades a math quiz. The quiz will give 2 problems for each of the arithmetic operations: +, -, *, /, and %. First, two addition problems will be presented (one at a time) with random numbers between 1 and 20. Then two subtraction problems, multiplication, division and modulus. For division use // and do floor division; for example: for 10//3, the answer should be 3. For an example of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT