Create an application that generates a quiz. Prompt for the user's first and last name, college major, and confidence in test taking (high, medium, or low). The quiz should contain at least five true/false questions about horticulture. When the user selects the correct answer, a message of positive reinforcement should be displayed. If the user selects the incorrect answer, the correct answer should be displayed with a message of constructive criticism. At the end of the quiz, display the number of correct and incorrect answers as well as the percentage of correct responses for each user. Make sure to address users by name and confirm or deny the correlation between their score and their perceived confidence in test taking.
Your code and output should show input and results for three different users taking the quiz. You cannot be one of the users. Make sure you use all the skills studied in the course, including proper comments, Scannerclass, several looping structures, and clean code without errors in any areas.
Code:
import java.util.Scanner;
public class HorticultureQuiz {
public static void main(String args[]){
String name;
String major;
String confidence;
Scanner input=new Scanner(System.in);
int correct=0, incorrect=0;
double CorrectPct;
String[] Questions=new String[]{"Question 1","Question 2","Question 3","Question 4","Question 5"};
boolean[] AnswerKey=new boolean[]{true, true,false,true,false}; //or whatever answer is
String[] Response =new String[]{"That's correct! Keep it up!","Sorry, wrong answer. Keep trying!"};
String answer;
System.out.print("Enter your first name: ");
name=input.next();
System.out.print("Enter your Major(one word): ");
major=input.next();
//get valid confidence
do{
System.out.print("Enter your confidence level( 'high','medium','low'): ");
confidence=input.next();
if(! (confidence.equals("high")||confidence.equals("medium")||confidence.equals("low"))){
System.out.print("What was that? We did not catch that.");
}
}while(! (confidence.equals("high")||confidence.equals("medium")||confidence.equals("low")));
//question time
for(int i=0;iSystem.out.printf("\nQuestion %d\nT or F: %s\n",i+1,Questions[i] );
answer=input.next();
if(answer.equals("T")||answer.equals("t")){
if(AnswerKey[i]==true){
correct++;
System.out.println(Response[0]);
}
else{
incorrect++;
System.out.println(Response[1]);
}
++;
}
else if(answer.equals("F")||answer.equals("f")){
if(AnswerKey[i]==false){
correct++;
System.out.println(Response[0]);
}
else{
incorrect++;
System.out.println(Response[1]);
}
i++;
}
else{
System.out.println("An invalid response was entered. Please enter 'T'or 'F' only");
}
}//end for
System.out.printf("%s, you got %d questions correct and %d questions wrong.",name,correct,incorrect);
System.out.printf("Your correct percentile is %.1f%%.",(float)correct*100/(float)(incorrect+correct));
input.close();
}//end main
}