question archive PART C - Dictionary 340 C++, 90 points Our satisfied clients are back to ask us to implement another interactive dictionary
Subject:Computer SciencePrice:9.82 Bought3
PART C - Dictionary 340 C++, 90 points Our satisfied clients are back to ask us to implement another interactive dictionary. Our dictionary takes input from users and uses the input as search key to look up values associated with the key. Requirements: - Coding: No hard coding, https://en.wikipedia.org/wiki/Hard_coding. Please think about Dynamic and Scalable. - Data Source: A text file, Data.CS.SFSU.txt . Please think about Software Deployment and Usability. Data Structure: Use existing data structure(s) or create new data structure(s) to store our dictionary's data. Each keyword, each part of speech, and each definition must be stored in a separate data field. Do not combine them such as storing three parts in one String. - Data Loading: When our program starts, it loads all the original data from the Data Source into our dictionary's data structure. The data source file is opened once and closed once per run. It must be closed as soon as possible. It must be closed before our program starts interacting with users. - User Interface: A program interface allows users to input search keys. This interface then displays returned results. Our program searches the dictionary's data (not the data source text file) for values associated with the search keys. - Identical Output: Our program's output must be identical to the complete sample run's output: Assignment-03_PC_Run.pdf
Interactive dictionary
Step-by-step explanation
import java.util.*;
public class Search
{
//create enum for all the pa
enum Speech
{
ADJECTIVE("Placeholder [adjective] :To be updated...."),
ADVERB("Placeholder [adverb] : To be updated..."),
CONJUNCTION("Placeholder [conjunction] : To be updated ..."),
INTERJUNCTION("Placeholder [injection] : 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 definit
enum Data
{
LOADING("! Loading data...."),
LOADING COMPLETED("! Loading compleated..."),
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 defination of csc210 used in this program
enum CSC210
{
ADJECTIVE1("CSC210 [adjective]:Comfortable with Objectives 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 vat
List<String> noFilter =new ArrayList<>;
noFilter.add(Speech.ADJECTIVE.value);
noFilter.add(Speech.ADJECTIVE.value);
noFilter.add(Speech.ADVERB.value);
noFilter.add(Speech.CONJECTIVE.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
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.ADJETIVE.value);
adjective.add(Speech.ADJETIVE.value);
List<String> csc210 = new ArrayList<>():
Arrays.stream(CSC210.values()).forEach(speech ->csc210.add(speech.value));
//Generating the dictionary ana mapping the key-value pairs
Map<String, Object> dictionary=new HashMap<>();
dictionary.put("",noFilter);
dictionary.put("distinct",distinct);
dictionary.put("noun", nonu);
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.
System.out.println();
//Taking the input search parameter from user and displaying the required data from the dictionary using the searh 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= s
earch = arr[1]+
System.out.println(" ((List<String>)dictionary.get(search)).stream().forEach(s ->{
System. out. println(" ");
System. out. println(s);
});
System.out.println(" ");
}
}
}