Question

In: Computer Science

Homework Description: Creating your own quiz As you likely have noticed, if you retook an ICON...

Homework Description: Creating your own quiz

As you likely have noticed, if you retook an ICON reading quiz in this course, you most likely received a different set of questions. This is because the questions are randomly selected from a question bank of possible questions where the number of questions on the quiz is (usually) less than the number of questions in the question bank. In this homework assignment, you will write your own question bank of at least 10 quiz questions (they do not have to be related to programming) and will write a menu-based program with three options: (1) take quiz, (2) view question statistics, and (3) quit. If option (1) from the menu is selected, the user should be presented with a random subset of three of the questions from your question bank (note: you should take care to make sure that none of your questions are repeated). After each question is presented, the user will provide an answer before the program presents the next question. It is up to you how your program informs the user as to how many and/or which questions he/she got correct on the quiz (e.g., displaying a message at the end of each question and/or at the end of the quiz). If option (2) from the menu is selected, the program should display (based on all quizzes that have been taken while your program has been running), for each question, the number of times the question has been asked and the number of times the question has been correct. To display this information, the formatting is up to you, but one option would be to display a fraction x/yx/y where xx is the number of correct answers and yy is the number of times the question has been asked. You should also display each question as the user doesn’t know the order of the questions in the question bank. Your menu-based program should continue to run until the user selects option 3 (note, you should use a blocking-while loop, or something similar, to make sure that the user enters a valid choice of 1, 2, or 3.)

Implementation hints

In creating your question bank, it is recommended that you create two arrays: one array (of strings) to store the quiz questions and one array (of integers) to store the correct quiz answers. All of your quiz answers should consistently be of the same type and it is recommended that you use integers to store the quiz answers. For example, the following code illustrates creating a question bank with only two questions (remember that you need at least 10 questions):

string questions[] = {"How many days are in January?", "How many days are in February (non-leap year)?"}; int answers[] = { 31, // January 28 }; // February (non-leap year)

Note, since questions that ask how many days are in a month is provided as an example, you may NOT use this as the theme for your questions. Please be creative and come up with your own questions.(Note, also consider the possibility of multiple choice questions with integer options (e.g., 1, 2, 3, 4).)

Solutions

Expert Solution

import java.util.*;
class Menu{
    public checkIfRepeat(int num, int[] repeat){
        for (int x = 0; x<3; x++){
            if (repeat[x]==num)
                return false
        }
        return true
    }
    
    
    public static void main(String at[]) throws Exception{
        Scanner R = new Scanner(System.in);
        //Setting up a question bank
        String[] ques = new String[]{'What is the capital of Chile?','What is the highest mountain in Britain?','What is the smallest country in the world?','Alberta is a province of which country?','How many countries still have the shilling as currency?','Which is the only vowel not used as the first letter in a US State?','What is the largest country in the world?','Where would you find the River Thames?','What is the hottest continent on Earth?','What is the longest river in the world?'};
        String[] ans = new String[]{'Santiago','Ben Nevis','Vatican City','Canada','Four – Kenya, Uganda, Tanzania and Somalia','E','Russia','London, UK','Africa','River Nile'}; 
        
        //Keeping Statistics
        int[] times = new int[]{0,0,0,0,0,0,0,0,0,0};
        int[] correct = new int[]{0,0,0,0,0,0,0,0,0,0};
        int[] repeat = new int[]{0,0,0}
        int quit = 0,count=0;
        
        System.out.println("Welcome to the Quiz!");
        while(quit==0){
            
            System.out.println("Enter your choice: ");
            System.out.println("1: Take Quiz \n2: View Question Statistics \n3: Quit \n");
            int choice = R.nextInt()
            switch(choice){
                //Take Quiz
                case 1:
                    //Returns number between 0-9 
                    int rand = ran.nextInt(10);
                    //Checking for repeats
                    while (count!=3){
                        //Checking if this random question has been repeated, if it hasn't only then will it display
                        if (checkIfRepeat(rand,repeat)){
                            repeat[count]=rand;
                            count++;
                            times[rand]++;

                            //Asking the question
                            System.out.println("Question No. "+ count + "!");
                            System.out.println(ques[rand]);
                            System.out.println("Your Answer: ");

                            //Taking the answer
                            String answer = R.nextLine();

                            //Checking the answer
                            if (answer.equalsIgnoreCase(ans[rand]){
                                correct[rand]++;
                                System.out.println("Correct!!\n");
                            }
                        }
                        else
                            rand = ran.nextInt(10);
                    }
                    count=0;
                    repeat = {0,0,0};
                    break;

                case 2:
                    System.out.println("Statistics: \n");
                    System.out.println("Questions attempted: \n");
                    int C=1;
                    for (int x=0;x<times.length){
                        if (times[x]>0){
                            System.out.print(C+". ");
                            System.out.println(ques[x]+"\tAsked: " + times[x] + "\tAnswered Correctly: " + correct[x])
                            C++;
                        }
                        
                    }
                    if (C==1)
                        System.out.println("No Question has been attempted\n");
                    break;

                case 3:
                    quit = 1;
                    break;
                
                default:
                    System.out.println("Give a correct option");
                }
            }       
        }
    }
}

Related Solutions

In this discussion, you will be creating your own application problems that your fellow classmates will...
In this discussion, you will be creating your own application problems that your fellow classmates will solve using systems of linear equations. Let’s first look at an example. When creating an application problem, it is helpful to begin with the solution to the problem. So, for example, if you start with the solutions (a rectangular garden with width = 8 ft, length = 10 ft), then you must find two ways these quantities relate to each other and give this...
For this problem you will be creating your own linear model for data of your choosing....
For this problem you will be creating your own linear model for data of your choosing. Please do the following: • Find a data set that you believe to be linear. You can measure and collect your own data or search the internet. Be sure to cite where you get your data. • Plot the data on a coordinate plane. Include a link to this graph in your submission of this assignment. • Approximate a slope and intercept for your...
HOMEWORK 8 - In your own words, describe the process of DNA replication -In your own...
HOMEWORK 8 - In your own words, describe the process of DNA replication -In your own words, provide a detailed description of how DNA is packaged in the nucleus (10 pts). -Identify the process and detail the steps of transcription from start to finish (In your own words) (10pts) -RNA is derived from DNA by what process and which major enzyme? (5pts) -What determines if a gene is functional (5 pts) -How do mutations occur in cells? Further list 3...
Creating a Proposal 1. Starting your own business Perhaps you have dreamed about one day owning...
Creating a Proposal 1. Starting your own business Perhaps you have dreamed about one day owning your own company, or maybe you have already started a business. Proposals are offers to a very specific audience with whom you hope to do business. Think of a product or service that you like or know something about. Your task Choose a product or service you would like to offer to a particular audience, such as a clothing line, a bakery featuring your...
You have noticed in your life that you are assisted particularly in difficult times? Who is...
You have noticed in your life that you are assisted particularly in difficult times? Who is it and how they support you?
Create Your Own Performance Measure:  The surgical floor has anecdotally noticed that patients who have received a...
Create Your Own Performance Measure:  The surgical floor has anecdotally noticed that patients who have received a spinal anesthetic are complaining more and more frequently of severe, persistent headache within four hours of surgery. The anesthesia department has decided that this needs further investigation. It is well established in the literature that spinal headaches can be avoided with proper education of staff and patients. 1. How can the anesthesia department establish whether a problem exists? 2. Develop a measurable statement that...
Create Your Own Performance Measure:  The surgical floor has anecdotally noticed that patients who have received a...
Create Your Own Performance Measure:  The surgical floor has anecdotally noticed that patients who have received a spinal anesthetic are complaining more and more frequently of severe, persistent headache within four hours of surgery. The anesthesia department has decided that this needs further investigation. It is well established in the literature that spinal headaches can be avoided with proper education of staff and patients. 1. How can the anesthesia department establish whether a problem exists? 2. Develop a measurable statement that...
For this homework we are going to walk you through creating a class. Lets look at...
For this homework we are going to walk you through creating a class. Lets look at a pizza restaurant and create a class for this. We will call our class pizza. The goal for every class is to include everything that has to happen for that class in 1 place. So whenever we create a class we need to think of what the nouns or variables will be for that class and then what the actions or methods will be...
Extra Practice / Homework 5) You are taking a multiple choice quiz which consists of 6...
Extra Practice / Homework 5) You are taking a multiple choice quiz which consists of 6 questions. Each question has five possible answers to choose from of which only one is correct. Answer the following questions a) What is your chance of choosing the correct answer for any particular problem? (express as a decimal rounded to two decimal places.) b) Explain how you could use your calculator to generate and use random numbers to simulate guessing on the each question...
You work the human resources in your county’s criminal justice department. You have noticed that it...
You work the human resources in your county’s criminal justice department. You have noticed that it seems that probation officers miss more days of work in a year than parole officers. You think they do but you want to be sure that the difference is significant. You collect data on the number of missed days of work and determine that the mean number of missed days for parole officers is 7 and the mean number of missed days for probation...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT