Question

In: Computer Science

PLEASE USE THE ECLIPSE. I want to make a program that shows whether the correct number...

PLEASE USE THE ECLIPSE.

I want to make a program that shows whether the correct number is correct or incorrect.

Example: how much is 1+1?

option 1: 2

option 2: 3

option 3: 4

option 4: 5

option 5: 6

The answer is 1. because the answer is 2 and the option number is 1.

Write a Java application that simulates a test. The test contains at least five questions about first three lectures of this course. Each question should be a multiple-choice question with 4 options.

Design a Test class. Use programmer-defined methods to implement your solution. For example:

  • create a method to simulate the questions – simulateQuestion
  • create a method to check the answer – checkAnswer
  • create a method to display a random message for the user – generateMessage
  • create a method to interact with the user - inputAnswer

For each question:

  • If the user finds the right answer, display a random congratulatory message (“Excellent!”,”Good!”,”Keep up the good work!”, or “Nice work!”).
  • If the user responds incorrectly, display an appropriate message and the correct answer (“No. Please try again”, “Wrong. Try once more”, “Don't give up!”, “No. Keep trying..”).
  • Use random-number generation to choose a number from 1 to 4 that will be used to select an appropriate response to each answer.
  • Use a switch statement to issue the responses, as in the following code:

switch ( randomObject.nextInt( 4 ) )

{

case 0:

return( "Very good!" );

……

}

At the end of the test display the number of correct and incorrect answers, and the percentage of the correct answers.

Your main class will simply create a Test object and start the test by calling inputAnswer method.

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. 

Let me know for any help with any other questions.

Thank You!
===========================================================================

public class Test {

    private String question;
    private String optionA;
    private String optionB;
    private String optionC;
    private String optionD;
    private String correctAnswer;
    private String userAnswer;

    private static Scanner scanner = new Scanner(System.in);
    private static Random random = new Random();

    public Test(String question, String optionA, String optionB, String optionC, String optionD, String correctAnswer) {
        this.question = question;
        this.optionA = optionA;
        this.optionB = optionB;
        this.optionC = optionC;
        this.optionD = optionD;
        this.correctAnswer = correctAnswer;
    }

    public void simulateQuestion() {

        System.out.println(question);
        System.out.println("Option 1: " + optionA);
        System.out.println("Option 2: " + optionB);
        System.out.println("Option 3: " + optionC);
        System.out.println("Option 4: " + optionD);

    }

    public void inputAnswer() {
        System.out.print("Enter the correct option [1-4] > ");
        userAnswer = scanner.nextLine();

    }

    public boolean checkAnswer() {
        return (userAnswer.equalsIgnoreCase(correctAnswer));

    }

    public void generateMessage() {

        if (checkAnswer()) {
            switch (random.nextInt(4)) {
                case 0:
                    System.out.println("Excellent");
                    break;
                case 1:
                    System.out.println("Good!");
                    break;
                case 2:
                    System.out.println("Keep up the good work!");
                    break;
                case 3:
                    System.out.println("Nice work!");
                    break;
            }
        } else {
            switch (random.nextInt(4)) {
                case 0:
                    System.out.println("No, Please try again");
                    break;
                case 1:
                    System.out.println("Wrong! Try once more.");
                    break;
                case 2:
                    System.out.println("Don't give up!");
                    break;
                case 3:
                    System.out.println("No keep trying!");
                    break;
            }
        }

    }
}

===================================================================

public class Tester {


    public static void main(String[] args) {

        Test[] tests = new Test[5];
        // chnage the question set here based on the three lectures of this course
        tests[0] = new Test("How much is 2+2?", "2", "3", "4", "5", "3");
        tests[1] = new Test("How much is 12/2?", "2", "6", "10", "12", "2");
        tests[2] = new Test("How much is 20-2?", "18", "22", "10", "0", "1");
        tests[3] = new Test("How much is 22+2?", "44", "24", "42", "20", "2");
        tests[4] = new Test("How much is 2+222?", "222", "220", "226", "224", "4");

        int corrects = 0, wrongs = 0;
        for (int i = 0; i < tests.length; i++) {
            System.out.println("Question #" + (i + 1) + "\n");
            tests[i].simulateQuestion();
            tests[i].inputAnswer();
            tests[i].generateMessage();
            if (tests[i].checkAnswer()) corrects += 1;
            else wrongs += 1;
            System.out.println();
        }

        System.out.printf("\nTotal Correct Answers : %2d (%5.2f)%%\n", corrects, (corrects * 100.0 / tests.length));
        System.out.printf("Total Wrong Answers   : %2d (%5.2f)%%\n", wrongs, (wrongs * 100.0 / tests.length));

    }
}

===================================================================


Related Solutions

I want to make picture compress program in matlab use eigenmatrix in RGB with PCA. This...
I want to make picture compress program in matlab use eigenmatrix in RGB with PCA. This code listed below. But this code is fail. I want to make the picture have a colour, but in my program the picture is still colorless. Can you fix my code? clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax -...
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1....
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1. You must call all of the defined functions above in your code. You may not change function names, parameters, or return types. 2. You must use a switch statement to check the user's menu option choice. 3. You may create additional functions in addition to the required functions listed above if you would like. 4. If user provides option which is not a choice...
Please use Java Eclipse and show code/output Please create a program that determines when a good...
Please use Java Eclipse and show code/output Please create a program that determines when a good day to go to the beach is. Please use the users input and its returning output. If the weather is 70 degree or greater, the program should say yes it is a good day to go If the weather is less than 70 degrees to say no the weather is not a good day to go
I need a NPV calculation. I just want to make sure I got it correct. Initial...
I need a NPV calculation. I just want to make sure I got it correct. Initial Cost at t=0 is $150 rate = 16% growth rate in perpetuity after year 5 at 1.5% Year 1 2 3 4 5 Cash Flow 5 11.4 14 21 28
When I wrote this code in the Eclipse program, I did not see a output .....
When I wrote this code in the Eclipse program, I did not see a output .. Why? _______ public class AClass { private int u ; private int v ; public void print(){ } public void set ( int x , int y ) { } public AClass { } public AClass ( int x , int y ) { } } class BClass extends AClass { private int w ; public void print() { System.out.println (" u + v...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
Please! I want the instructions of how to solve it, not the answer. Write a program...
Please! I want the instructions of how to solve it, not the answer. Write a program that does the following in order: 1. Asks the user to enter a name 2. Asks the user to enter a number “x” 3. Asks the user to enter a number “y” 4. Calculates the sum of “x” and “y” 5. Prints out the number for “x”, “y” and “sum” An example of the program input and output is shown below: Enter your name:...
Hi there, We want to make a correct formulation of the problem that want to apply...
Hi there, We want to make a correct formulation of the problem that want to apply Linear programming on it.. we went to a store that is selling surveillance system (Esp. cameras called UNV (uniview products)) we need to know what is the possible constraints to be considered in order to maximize the profit. :)
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
This program is supposed to identify whether I inputted a number or a letter through enumerated...
This program is supposed to identify whether I inputted a number or a letter through enumerated types and an array of messages. I'm aware that you can't compare strings and enums but I'm out of ideas. What method do you suggest. #include <iostream> #include <iomanip> using namespace std; int main() {    enum letters { A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT