Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package hwchapter7;
- /**
- *
- * @author crist
- */
- import java.util.Scanner;
- public class DriverExam {
- public static String[] inputAnswers = new String[20];
- public static Scanner input = new Scanner(System.in);
- public static int total = 0;
- public static String correctAnswers[] = {"B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A"};
- public static void main(String[] args) {
- examAnswers();
- }
- public static void examAnswers() {
- for (int i = 0; i < inputAnswers.length; i++) {
- System.out.println("Enter the Answer letter for Question " + (i + 1));
- inputAnswers[i] = input.nextLine();
- if (!inputAnswers[i].equalsIgnoreCase("A") && !inputAnswers[i].equalsIgnoreCase("B") && !inputAnswers[i].equalsIgnoreCase("C") && !inputAnswers[i].equalsIgnoreCase("D")) {
- i--;
- System.out.println("Wrong input");}
- else if (inputAnswers[i].equalsIgnoreCase(correctAnswers[i])) {
- total++; }
- else if (!inputAnswers[i].equalsIgnoreCase(correctAnswers[i])) {
- System.out.println("The correct answer is: " + correctAnswers[i]);
- System.out.println(" ");
- } else {
- System.out.println(" ");
- }
- }
- totalCorrect();
- totalIncorrect();
- System.out.println(passedStudent());
- }
- public static void totalCorrect() {
- System.out.println("The TOTAL correct answers are: " + total);
- }
- public static void totalIncorrect() {
- System.out.println("The TOTAL incorrect answers are: " + (20 - total));
- }
- public static boolean passedStudent() {
- if (total >= 15) {
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement