Question

In: Computer Science

PLEASE Use the ECLIPSE... AND FOLLOW THIS RULES.. Apply the naming conventions for variables, methods, classes,...

PLEASE Use the ECLIPSE...

AND FOLLOW THIS RULES..

Apply the naming conventions for variables, methods, classes, and packages:

- variable names start with a lowercase character

- classes start with an uppercase character

- packages use only lowercase characters

methods start with a lowercase character

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 input answer method.

Thank you.

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. 

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!

Note: Please change the questions based on you lecture classes. Run the Tester.java class.
===========================================================================



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

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.println("Enter the correct answer? ");
        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","4");
        tests[1] = new Test("How much is 12/2?","2","6","10","12","6");
        tests[2] = new Test("How much is 20-2?","18","22","10","0","18");
        tests[3] = new Test("How much is 22+2?","44","24","42","20","24");
        tests[4] = new Test("How much is 2+222?","222","220","226","224","224");

        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

Please Use the ECLIPSE AND FOLLOW THESE RULES Apply the naming conventions for variables, methods, classes,...
Please Use the ECLIPSE AND FOLLOW THESE RULES Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character - classes start with an uppercase character - packages use only lowercase characters methods start with a lowercase character question1: Design a Lotto class with one array instance variable to hold three random integer values (from 1 to 9). Include a constructor that randomly populates the array for a lotto object. Also, include a...
Please change this code to follow the rules. The program must not use global variables. In...
Please change this code to follow the rules. The program must not use global variables. In another words, it must use local variables and pass-by-value or pass-by-reference parameters. #include <iostream> #include <string> #include <algorithm> using namespace std; struct expense { string Desc; double exp; }; expense arr[100]; int c = 0; void menu(); //1. show all void showArray(){ if (c>0){ for(int i=0;i<c;i++){ cout<<"AMOUNT("<<arr[i].exp<<") DESC"<<arr[i].Desc<<")"<<endl; } }else{ cout<<"There is no expense entry available"; } menu(); } //2. spend void addArray(){ string...
Discuss why naming conventions are important and why as a programmer you should consistently follow them....
Discuss why naming conventions are important and why as a programmer you should consistently follow them. Include in this discussion, problems that could arise in naming variables if one convention is NOT followed.
Please focus on Nurse Practitioners 1. Discuss the controversy surrounding the naming conventions for APRNs (example...
Please focus on Nurse Practitioners 1. Discuss the controversy surrounding the naming conventions for APRNs (example DNP prepared nurse practitioners using the title "doctor")
use eclipse Develop the classes for the following requirements: 1. A class named Employee (general, for...
use eclipse Develop the classes for the following requirements: 1. A class named Employee (general, for college) 2. A class named Instructor (more specific, for college) 3. A class named Staff (more specific, for college, HR officer, Marking staff) Tasks: 1. Figure out the relationships among the classes; 2. Determine the abstract class, and the child classes; 3. For the abstract class, determine at least one abstract method; 4. Each class should at least two data members and one extra...
7. Explain the use and rules that apply to C Corporation subsidiaries.
7. Explain the use and rules that apply to C Corporation subsidiaries.
   Assignment ID is p1 NOTE: Algebraic expressions follow FORTRAN conventions. Use full calculator precision for...
   Assignment ID is p1 NOTE: Algebraic expressions follow FORTRAN conventions. Use full calculator precision for intermediate values. Use the bisection method with the function defined by: A=(X + 1.62) / 5.39 B=(X - 3.77) / 5.39 P1=((A-1)**2)*(1+2*A) P2=((B+1)**2)*(1-2*B) F(X) = (P1 * (-1.24) ) + (P2 * 4.13) Start with interval (Xleft,Xright) = (-1.62, 3.77) The function values at these end points are F(Xleft) = -1.24 F(Xright) = 4.13 The new approximation interval bracketing the root after ONE bisection...
Which of the following are characteristics of NeoclassicalEconomics? (Select all that apply)individuals use rules...
Which of the following are characteristics of Neoclassical Economics? (Select all that apply)individuals use rules of thumbindividuals act independently of one anotherreference points matterrational preferencesindividuals use mental accountingfirms maximize profits
PLEASE NUMBER EACH ANSWER Students will use advanced looping methods including replicate(), lapply(), sapply(), and apply(),...
PLEASE NUMBER EACH ANSWER Students will use advanced looping methods including replicate(), lapply(), sapply(), and apply(), and access datasets provided with R packages in an R script. The function call, rnorm(1), generates a normal random number. Use replicate() to generate 10 normal random numbers and assign them to a vector called nums. The R statement, data(iris), loads the built-in R data set iris. This dataset has 150 rows and 5 columns. The 5 column names are "Sepal.Length","Sepal.Width","Petal.Length","Petal.Width" and "Species". Write...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT