Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 39 additions & 2 deletions src/flashcards/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
package flashcards;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
System.out.print("Hello world!");

public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
System.out.printf("Input the number of cards:\n");

int numCards = Integer.parseInt(scanner.nextLine());

Map<String, String> cardToDefinition = new LinkedHashMap<>();
Map<String, String> definitionToCard = new LinkedHashMap<>();

for (int i = 0; i < numCards; i++) {
System.out.printf("The card #%d:\n", i + 1);
String card = scanner.nextLine();
System.out.printf("The definition of the card #%d:\n", i + 1);
String definition = scanner.nextLine();
cardToDefinition.put(card, definition);
definitionToCard.put(definition, card);
}

for (String card : cardToDefinition.keySet()) {
System.out.printf("Print the definition of \"%s\":\n", card);
String guess = scanner.nextLine();
if (definitionToCard.containsKey(guess) && cardToDefinition.get(card).equals(guess)) {
System.out.printf("Correct answer. ");
} else if (definitionToCard.containsKey(guess)) {
System.out.printf(
"Wrong answer (the correct one is \"%s\", you've just written a definition of \"%s\" card). ",
cardToDefinition.get(card), definitionToCard.get(guess));
} else {
System.out
.printf("Wrong answer (the correct one is \"%s\").", cardToDefinition.get(card));
}
}
}
}
}