Guest User

Untitled

a guest
Oct 21st, 2019
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // score attempts to give female computer scientists
  2. public static void computerScientists ()
  3. {
  4. int score = 0;
  5. print_instructions();
  6. score = choices(score);
  7. print_score(score);
  8. }
  9. // Give the quiz instructions
  10. public static void print_instructions ()
  11. {
  12. 22
  13. print("Name three female computer scientists from: \n Turing,
  14. Lovelace, Babbage, Hopper, and Liskov");
  15. }
  16. // print a given message
  17. public static void print (String s)
  18. {
  19. JOptionPane.showMessageDialog(null, s);
  20. }
  21. // Print a given score
  22. public static void print_score (int total)
  23. {
  24. print("You got " + total + " right");
  25. }
  26. // Give a person 3 tries to name computer scientists
  27. public static int choices (int total)
  28. {
  29. final int TRIES = 3;
  30. for(int i = 1; i <= TRIES; i++)
  31. {
  32. String answer = input(i + ". Pick a Computer Scientist:");
  33.  
  34. total = total + check_answer(answer);
  35. }
  36. return total;
  37. }
  38. // print a message and input a String value
  39. public static String input (String s)
  40. {
  41. return JOptionPane.showInputDialog(s);
  42. }
  43. // Check the name given, printing a message and
  44. // returning the points for that answer
  45. public static int check_answer (String answer)
  46. {
  47. int points;
  48. if (answer.equals("Turing"))
  49. {
  50. points = male(answer);
  51. }
  52. else if (answer.equals("Babbage"))
  53. {
  54. points = male(answer);
  55. }
  56. else if (answer.equals("Lovelace"))
  57. {
  58. points = female(answer);
  59. }
  60. else if (answer.equals("Hopper"))
  61. {
  62. points = female(answer);
  63. }
  64. else if (answer.equals("Liskov"))
  65. {
  66. points = female(answer);
  67. }
  68. else
  69. {
  70. 23
  71. points = unknown(answer);
  72. }
  73. return points;
  74. }
  75. // If male score is 0
  76. public static int male (String answer)
  77. {
  78. print("Sorry, " + answer + " is a man");
  79. return 0;
  80. }
  81. // If female score is 1
  82. public static int female (String answer)
  83. {
  84. print("Yes, " + answer + " is female");
  85. return 1;
  86. }
  87. // If unknown score is 0
  88. public static int unknown (String answer)
  89. {
  90. print( "I've not heard of " + answer);
  91. return 0;
  92. }
RAW Paste Data