Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // score attempts to give female computer scientists
- public static void computerScientists ()
- {
- int score = 0;
- print_instructions();
- score = choices(score);
- print_score(score);
- }
- // Give the quiz instructions
- public static void print_instructions ()
- {
- 22
- print("Name three female computer scientists from: \n Turing,
- Lovelace, Babbage, Hopper, and Liskov");
- }
- // print a given message
- public static void print (String s)
- {
- JOptionPane.showMessageDialog(null, s);
- }
- // Print a given score
- public static void print_score (int total)
- {
- print("You got " + total + " right");
- }
- // Give a person 3 tries to name computer scientists
- public static int choices (int total)
- {
- final int TRIES = 3;
- for(int i = 1; i <= TRIES; i++)
- {
- String answer = input(i + ". Pick a Computer Scientist:");
- total = total + check_answer(answer);
- }
- return total;
- }
- // print a message and input a String value
- public static String input (String s)
- {
- return JOptionPane.showInputDialog(s);
- }
- // Check the name given, printing a message and
- // returning the points for that answer
- public static int check_answer (String answer)
- {
- int points;
- if (answer.equals("Turing"))
- {
- points = male(answer);
- }
- else if (answer.equals("Babbage"))
- {
- points = male(answer);
- }
- else if (answer.equals("Lovelace"))
- {
- points = female(answer);
- }
- else if (answer.equals("Hopper"))
- {
- points = female(answer);
- }
- else if (answer.equals("Liskov"))
- {
- points = female(answer);
- }
- else
- {
- 23
- points = unknown(answer);
- }
- return points;
- }
- // If male score is 0
- public static int male (String answer)
- {
- print("Sorry, " + answer + " is a man");
- return 0;
- }
- // If female score is 1
- public static int female (String answer)
- {
- print("Yes, " + answer + " is female");
- return 1;
- }
- // If unknown score is 0
- public static int unknown (String answer)
- {
- print( "I've not heard of " + answer);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement