From e995574fa0003bf8f18b537d550d66c950a0a469 Mon Sep 17 00:00:00 2001 From: aleks Date: Wed, 19 Dec 2018 17:05:50 +0300 Subject: [PATCH 1/3] Stage 3 Completed. --- .idea/misc.xml | 2 +- src/flashcards/Main.java | 2 +- src/flashcards/cards.java | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/flashcards/cards.java diff --git a/.idea/misc.xml b/.idea/misc.xml index a165cb3..cbb200f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/flashcards/Main.java b/src/flashcards/Main.java index d1b036c..056928e 100644 --- a/src/flashcards/Main.java +++ b/src/flashcards/Main.java @@ -2,6 +2,6 @@ public class Main { public static void main(String[] args) { - System.out.print("Hello world!"); + cards.cardInput(); } } \ No newline at end of file diff --git a/src/flashcards/cards.java b/src/flashcards/cards.java new file mode 100644 index 0000000..f6ee2c8 --- /dev/null +++ b/src/flashcards/cards.java @@ -0,0 +1,33 @@ +package flashcards; + +import java.util.Scanner; + +public class cards { + + protected static void cardInput(){ + Scanner input = new Scanner(System.in); + //ask user for input number of cards + System.out.println("Input the number of cards: "); + int numOfCards = input.nextInt(); + //Array's for storing cards and definitions + String[] card = new String[numOfCards]; + String[] definition = new String[numOfCards]; + //for loop for getting cards from user and put them in arrays + for (int i = 0; i < numOfCards; i++){ + System.out.println("The card #" + (i + 1) + ": "); + card[i] = input.nextLine(); + System.out.println("The definition of the card #" + (i + 1) + ": "); + definition[i] = input.nextLine(); + } + //iterate over cards and ask for answer + for (int i = 0; i < card.length; i++){ + System.out.println("Print the definition of " + card[i] + ": "); + String answer = input.nextLine(); + if (answer.equals(definition[i])){ + System.out.println("Correct answer."); + } else { + System.out.println("Wrong answer (the correct one is \"" + definition[i] + "\")"); + } + } + } +} From 2df4b0c211e4ee6083cfd6fbe30fc13326b81f87 Mon Sep 17 00:00:00 2001 From: aleks Date: Thu, 20 Dec 2018 14:25:53 +0300 Subject: [PATCH 2/3] Stage 4 Completed. --- src/flashcards/cards.java | 60 ++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/src/flashcards/cards.java b/src/flashcards/cards.java index f6ee2c8..68be703 100644 --- a/src/flashcards/cards.java +++ b/src/flashcards/cards.java @@ -1,33 +1,53 @@ package flashcards; -import java.util.Scanner; +import java.util.*; + +import static java.lang.System.*; public class cards { protected static void cardInput(){ - Scanner input = new Scanner(System.in); + Scanner input = new Scanner(in); //ask user for input number of cards - System.out.println("Input the number of cards: "); + out.println("Input the number of cards: "); int numOfCards = input.nextInt(); - //Array's for storing cards and definitions - String[] card = new String[numOfCards]; - String[] definition = new String[numOfCards]; - //for loop for getting cards from user and put them in arrays - for (int i = 0; i < numOfCards; i++){ - System.out.println("The card #" + (i + 1) + ": "); - card[i] = input.nextLine(); - System.out.println("The definition of the card #" + (i + 1) + ": "); - definition[i] = input.nextLine(); - } - //iterate over cards and ask for answer - for (int i = 0; i < card.length; i++){ - System.out.println("Print the definition of " + card[i] + ": "); - String answer = input.nextLine(); - if (answer.equals(definition[i])){ - System.out.println("Correct answer."); + //HashMap's for storing cards and definitions + Map cardToDefinition = new HashMap(); + Map definitionToCard = new HashMap(); + //loop for populating HashMap with values + for(int i = 0; i < numOfCards; i++){ + out.println("The card #" + i +":"); + String cardValue = input.nextLine(); + out.println("The definition of the card #" + i +":"); + String defValue = input.nextLine(); + if(cardToDefinition.containsKey(cardValue) || definitionToCard.containsKey(defValue)){ + out.println("Please reenter new value"); + if (i > 0) { + i--; + } else { + i = 0; + } } else { - System.out.println("Wrong answer (the correct one is \"" + definition[i] + "\")"); + cardToDefinition.put(cardValue, defValue); + definitionToCard.put(defValue, cardValue); } } + //loop for answering questions + cardToDefinition.forEach((key, value) ->{ + System.out.println("Print the definition of: " + key); + String userAnswer = input.nextLine(); + if (!value.equals(userAnswer) && definitionToCard.containsKey(userAnswer)){ + System.out.println("Wrong answer (the correct one is \"" + value +"\", you've just written a definition of \"" + definitionToCard.get(userAnswer) + "\" card). Print the definition of \"" + definitionToCard.get(userAnswer) + "\":"); + userAnswer = input.nextLine(); + if (cardToDefinition.containsKey(userAnswer)){ + out.println("Correct"); + } else { + System.out.println(cardToDefinition.get(userAnswer)); + } + } else { + System.out.println("Correct"); + } + + }); } } From 642e4f24e2ff6c92c0ae154fe327eba77b2cceff Mon Sep 17 00:00:00 2001 From: aleks Date: Thu, 20 Dec 2018 19:34:27 +0300 Subject: [PATCH 3/3] Stage 5 Main_Menu. --- src/flashcards/Main.java | 2 +- src/flashcards/cards.java | 84 +++++++++++++++++++-------------------- 2 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/flashcards/Main.java b/src/flashcards/Main.java index 056928e..f452ff8 100644 --- a/src/flashcards/Main.java +++ b/src/flashcards/Main.java @@ -2,6 +2,6 @@ public class Main { public static void main(String[] args) { - cards.cardInput(); + cards.mainMenu(); } } \ No newline at end of file diff --git a/src/flashcards/cards.java b/src/flashcards/cards.java index 68be703..d8453ce 100644 --- a/src/flashcards/cards.java +++ b/src/flashcards/cards.java @@ -2,52 +2,48 @@ import java.util.*; -import static java.lang.System.*; - public class cards { - - protected static void cardInput(){ - Scanner input = new Scanner(in); - //ask user for input number of cards - out.println("Input the number of cards: "); - int numOfCards = input.nextInt(); - //HashMap's for storing cards and definitions - Map cardToDefinition = new HashMap(); - Map definitionToCard = new HashMap(); - //loop for populating HashMap with values - for(int i = 0; i < numOfCards; i++){ - out.println("The card #" + i +":"); - String cardValue = input.nextLine(); - out.println("The definition of the card #" + i +":"); - String defValue = input.nextLine(); - if(cardToDefinition.containsKey(cardValue) || definitionToCard.containsKey(defValue)){ - out.println("Please reenter new value"); - if (i > 0) { - i--; - } else { - i = 0; - } - } else { - cardToDefinition.put(cardValue, defValue); - definitionToCard.put(defValue, cardValue); - } + //main subroutine for choosing menu items + protected static void mainMenu(){ + Scanner scan = new Scanner(System.in); + System.out.print("Input the action (add, remove, import, export, ask, exit): "); + String menuChoice = scan.nextLine(); + switch (menuChoice){ + case "add": + break; + case "remove": + break; + case "import": + break; + case "export": + break; + case "ask": + break; + case "exit": + exit(); + break; } - //loop for answering questions - cardToDefinition.forEach((key, value) ->{ - System.out.println("Print the definition of: " + key); - String userAnswer = input.nextLine(); - if (!value.equals(userAnswer) && definitionToCard.containsKey(userAnswer)){ - System.out.println("Wrong answer (the correct one is \"" + value +"\", you've just written a definition of \"" + definitionToCard.get(userAnswer) + "\" card). Print the definition of \"" + definitionToCard.get(userAnswer) + "\":"); - userAnswer = input.nextLine(); - if (cardToDefinition.containsKey(userAnswer)){ - out.println("Correct"); - } else { - System.out.println(cardToDefinition.get(userAnswer)); - } - } else { - System.out.println("Correct"); - } + } + //subroutine for adding cards + protected static void addCard(){ - }); } + //subroutine for removing cards + protected static void removeCard(){ + } + //subroutine for import + protected static void importCard(){ + } + //subroutine for export + protected static void exportCard(){ + } + //subroutine for asking user + protected static void askCard(){ + } + //exit subroutine + protected static void exit(){ + System.out.println("Bye bye!"); + System.exit(0); + } + }