Advertisement
Ccuevas3410

Untitled

Sep 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hwchapter7;
  7.  
  8. /**
  9. *
  10. * @author crist
  11. */
  12. import java.util.Scanner;
  13.  
  14. public class DriverExam {
  15.  
  16. public static String[] inputAnswers = new String[20];
  17. public static Scanner input = new Scanner(System.in);
  18. public static int total = 0;
  19. public static String correctAnswers[] = {"B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A"};
  20.  
  21. public static void main(String[] args) {
  22.  
  23. examAnswers();
  24.  
  25. }
  26.  
  27. public static void examAnswers() {
  28.  
  29. for (int i = 0; i < inputAnswers.length; i++) {
  30.  
  31. System.out.println("Enter the Answer letter for Question " + (i + 1));
  32.  
  33. inputAnswers[i] = input.nextLine();
  34.  
  35. if (!inputAnswers[i].equalsIgnoreCase("A") && !inputAnswers[i].equalsIgnoreCase("B") && !inputAnswers[i].equalsIgnoreCase("C") && !inputAnswers[i].equalsIgnoreCase("D")) {
  36. i--;
  37. System.out.println("Wrong input");}
  38.  
  39. else if (inputAnswers[i].equalsIgnoreCase(correctAnswers[i])) {
  40. total++; }
  41. else if (!inputAnswers[i].equalsIgnoreCase(correctAnswers[i])) {
  42. System.out.println("The correct answer is: " + correctAnswers[i]);
  43. System.out.println(" ");
  44.  
  45.  
  46.  
  47. } else {
  48.  
  49. System.out.println(" ");
  50. }
  51.  
  52. }
  53. totalCorrect();
  54. totalIncorrect();
  55. System.out.println(passedStudent());
  56.  
  57. }
  58.  
  59. public static void totalCorrect() {
  60. System.out.println("The TOTAL correct answers are: " + total);
  61.  
  62. }
  63.  
  64. public static void totalIncorrect() {
  65. System.out.println("The TOTAL incorrect answers are: " + (20 - total));
  66. }
  67.  
  68. public static boolean passedStudent() {
  69. if (total >= 15) {
  70. return true;
  71. } else {
  72. return false;
  73. }
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement