Question

Store the original data in a set of enum objects.

Store the original data in a set of enum objects.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

public class Search {

   //create enum for all the parts of speech
   enum Speech
   {
       ADJECTIVE("Placeholder [adjective] : To be updated..."),
       ADVERB("Placeholder [adverb] : To be updated..."),
       CONJUNCTION("Placeholder [conjunction] : To be updated..."),
       INTERJUNCTION("Placeholder [interjunction] : To be updated..."),
       NOUN("Placeholder [noun] : To be updated..."),
       PREPOSITION("Placeholder [preposition] : To be updated..."),
       PRONOUN("Placeholder [pronoun] : To be updated..."),
       VERB("Placeholder [verb] : To be updated...");

       private String value;
       Speech(String s) {
           this.value = s;
       }

       public String getValue() {
           return value;
       }
   };

   //creating enum for definitions used in this program
   enum Data
   {
       LOADING("! Loading data..."),
       LOADING_COMPLETED("! Loading completed..."),
       PRINT("-----DICTIONARY 340 JAVA----"),
       OOPS("<2nd argument must be a part of a speech or \"distinct\""),
       SEARCH("Search: ");

       private String value;
       Data(String s) {
           this.value = s;
       }

       public String getValue() {
           return value;
       }
   };

   //creating enum for all the definitions of CSC210 used in this program
   enum CSC210
   {
       ADJECTIVE1("CSC210 [adjective] : Comfortable with Objects and Classes"),
       ADJECTIVE2("CSC210 [adjective] : Ready for CSC 220"),
       NOUN("CSC210 [noun]Intro to Java "),
       VERB("CSC210 [verb] : To learn Java");

       private String value;
       CSC210(String s) {
           this.value = s;
       }

       public String getValue() {
           return value;
       }
   };

   public static void main(String[] args) {

       System.out.println(Data.LOADING.getValue());
       
       //Generating all the values required in the dictionary by using the values from enum
       List<String> noFilter = new ArrayList<>();
       noFilter.add(Speech.ADJECTIVE.value);
       noFilter.add(Speech.ADJECTIVE.value);
       noFilter.add(Speech.ADVERB.value);
       noFilter.add(Speech.CONJUNCTION.value);
       noFilter.add(Speech.INTERJUNCTION.value);
       noFilter.add(Speech.NOUN.value);
       noFilter.add(Speech.NOUN.value);
       noFilter.add(Speech.NOUN.value);
       noFilter.add(Speech.PREPOSITION.value);
       noFilter.add(Speech.PRONOUN.value);
       noFilter.add(Speech.VERB.value);

       List<String> distinct = new ArrayList<>();
       Arrays.stream(Speech.values()).forEach(speech -> distinct.add(speech.value));

       List<String> noun = new ArrayList<>();
       noun.add(Speech.NOUN.value);
       noun.add(Speech.NOUN.value);
       noun.add(Speech.NOUN.value);

       List<String> nounDistinct = new ArrayList<>();
       nounDistinct.add(Speech.NOUN.value);

       List<String> adjective = new ArrayList<>();
       adjective.add(Speech.ADJECTIVE.value);
       adjective.add(Speech.ADJECTIVE.value);

       List<String> csc210 = new ArrayList<>();
       Arrays.stream(CSC210.values()).forEach(speech -> csc210.add(speech.value));

       //Generating the dictionary and mapping the key-value pairs
       Map<String, Object> dictionary = new HashMap<>();
       dictionary.put("",noFilter);
       dictionary.put("distinct", distinct);
       dictionary.put("noun", noun);
       dictionary.put("noundistinct", nounDistinct);
       dictionary.put("adjective", adjective);
       dictionary.put("oops", Arrays.asList(Data.OOPS.getValue()));
       dictionary.put("csc210", csc210);

       System.out.println(Data.LOADING_COMPLETED.getValue());
       System.out.println();
       System.out.println(Data.PRINT.getValue());
       System.out.println();

       //Taking the input search parameter from user and displaying the required data from the dictionary using the search key
       while (true) {
           Scanner reader = new Scanner(System.in);
           String userInput = null;
           String search = null;
           System.out.print(Data.SEARCH.getValue());
           userInput = reader.nextLine();

           //checking the number of arguments given by the user and handling the program accordingly so that it will not break
           String[] arr=userInput.split(" ");
           if (arr.length==1)
               search = "";
           else if (arr.length==2)
               search = arr[1];
           else if (arr.length==3)
               search = arr[1]+arr[2];
           System.out.println("   |" );
           ((List<String>)dictionary.get(search)).stream().forEach(s -> {
               System.out.print("     ");
               System.out.println(s);
           });
           System.out.println("   |" );
       }
   }

}

Add a comment
Know the answer?
Add Answer to:
Store the original data in a set of enum objects.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT