コード例 #1
0
ファイル: prog3.java プロジェクト: theraptor42/CS-102
  /*
  Method: addNewEntry - user interface
  Purpose: word menu, interacts with user and calls database methods
              to add new entries, prints out results
  Parameters:
      Database currentThesaurus   the database parsed from the text file
  Returns:
      none
  */
  public static void addNewEntry(Database currentThesaurus) {
    System.out.println("\nPlease type the word you would like to add");
    System.out.print(">>");
    // Will accept spaces in words
    // Scanner to take user input
    Scanner inputScanner = new Scanner(System.in);
    // the wood the user wants to add
    String newUserWord = inputScanner.nextLine();

    // checks whether the word was added successfully
    boolean successCheck = currentThesaurus.addEntryFromMenu(newUserWord);
    if (successCheck == true) {
      System.out.println("\n" + newUserWord + " has been " + "added to the thesaurus");
      System.out.println("Would you like to add a synonym for it?");
      System.out.print("type (yes/no) >>");
      // does the user want to add a synonym
      String userResponse = inputScanner.next();
      if (userResponse.equalsIgnoreCase("yes")) {
        // calls the same method that addNewSynonym calls
        currentThesaurus.addSynonymFromMenu(newUserWord);
      } else {
        System.out.println("\nGoing back to the main menu");
      }
    } else {
      System.out.println("\nSorry, that word is already in the thesaurus\n");
      System.out.println("Going back to the main menu");
      // returns to the main menu
    }
  }
コード例 #2
0
ファイル: prog3.java プロジェクト: theraptor42/CS-102
  /*
  Method: addNewSynonym - basic user interface
  Purpose: word menu, interacts with user and calls database methods
              to add new synonyms
              real work is done in database
  Parameters:
      Database currentThesaurus   the database parsed from the text file
  Returns:
      none
  */
  public static void addNewSynonymToEntry(Database currentThesaurus) {
    System.out.println("\nPlease type the word you would like to update");
    System.out.print(">>");
    // Scanner to take user input
    Scanner inputScanner = new Scanner(System.in);
    // What word does the user want to update?
    String word = inputScanner.nextLine();

    // calls the method where the real work is done
    currentThesaurus.addSynonymFromMenu(word);
    // written that way so code is usable by addNewEntry
  }