Advertisement
Guest User

Untitled

a guest
Mar 26th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. package flashcards;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static final Scanner scanner = new Scanner(System.in);
  7.  
  8.     public static void main(String[] args) {
  9.         int numberOfCards = numberOfCardsQuestion();
  10.         String[] terms = new String[numberOfCards];
  11.         String[] definitions = new String[numberOfCards];
  12.  
  13.         buildingQuestionsDatabase(terms, definitions, numberOfCards);
  14.  
  15.         theGame(terms, definitions, numberOfCards);
  16.     }
  17.  
  18.     private static void theGame(String[] terms, String[] definitions, int numberOfCards) {
  19.         String answer;
  20.         for (int i = 0; i < numberOfCards; i++) {
  21.             System.out.println("Print the definition of \"" + terms[i] + "\":");
  22.             answer = scanner.next();
  23.             if (answer.equals(definitions[i])) {
  24.                 System.out.println(Results.CORRECT.getResultOutput());
  25.             } else {
  26.                 System.out.print(Results.WRONG.getResultOutput() + definitions[i] + "\".");
  27.             }
  28.         }
  29.     }
  30.  
  31.  
  32.     private static void buildingQuestionsDatabase(String[] terms, String[] definitions, int numberOfCards) {
  33.         for (int i = 0; i < numberOfCards; i++) {
  34.             System.out.println("The card #" + (i + 1) + ":");
  35.             terms[i] = scanner.next();
  36.             System.out.println("The definition of the card #" + (i + 1) + ":");
  37.             definitions[i] = scanner.next();
  38.         }
  39.     }
  40.  
  41.     private static int numberOfCardsQuestion() {
  42.         System.out.println("Input the number of cards:");
  43.         int numberOfCards = scanner.nextInt();
  44.         return numberOfCards;
  45.     }
  46. }
  47.  
  48. package flashcards;
  49.  
  50. public enum Results {
  51.     CORRECT ("Correct answer."),
  52.     WRONG ("Wrong answer. The correct one is \"");
  53.  
  54. private final String resultOutput;
  55.  
  56.     Results(String resultOutput) {
  57.         this.resultOutput = resultOutput;
  58.     }
  59.  
  60.     public String getResultOutput() {
  61.         return resultOutput;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement