Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You should implement the following classes according to the UML diagrams. Be sur

ID: 3866583 • Letter: Y

Question

You should implement the following classes according to the UML diagrams. Be sure to include a small comment for at least cach non-trivial method. You will also need to implement the following three new (non-checked) exception classes. When to throw and catch these exceptions are briefly described below, but are left mostly up to you to figure out. 1. DictionaryFormatException 2. EmptyWordListException 3. UnsupportedCategory Exception Dictionary - nouns: List verbs: List - adjectives: List - adverbs: List -pronouns: List - interjections: List + addWord(line: String + get Word(partOfSpeech: String): String 1. The addWord method takes a line which is expected to be in the for- mat pos: word, where pos is the part of speech of word. This method should add word to the appropriate list corresponding to pos. This methood throws an UnsupportedCategoryException if the part of speech does not

Explanation / Answer

Please find below the class implementations :

Dictonary.java

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

public class Dictonary {

private List<String> nouns = new ArrayList<String>();
private List<String> verbs = new ArrayList<String>();
private List<String> adjectives = new ArrayList<String>();
private List<String> adverbs = new ArrayList<String>();
private List<String> pronouns = new ArrayList<String>();
private List<String> interjections = new ArrayList<String>();

public List<String> getNouns() {
return nouns;
}
public void setNouns(List<String> nouns) {
this.nouns = nouns;
}
public List<String> getVerbs() {
return verbs;
}
public void setVerbs(List<String> verbs) {
this.verbs = verbs;
}
public List<String> getAdjectives() {
return adjectives;
}
public void setAdjectives(List<String> adjectives) {
this.adjectives = adjectives;
}
public List<String> getAdverbs() {
return adverbs;
}
public void setAdverbs(List<String> adverbs) {
this.adverbs = adverbs;
}
public List<String> getPronouns() {
return pronouns;
}
public void setPronouns(List<String> pronouns) {
this.pronouns = pronouns;
}
public List<String> getInterjections() {
return interjections;
}
public void setInterjections(List<String> interjections) {
this.interjections = interjections;
}

/*PART 1 :
* .trim() function checks for any preceding or trailing spaces,
* If the .split() operating on the string
* results into two elements that means the line
* is in specified format. i.e. pos : word
*
* PART 2:
* if the partOfSpechOfWord does not match with any given
* then it is presumed to throw UnsupportedCategoryException
*/
public void addWord(String line) throws DictionaryFormatException, UnsupportedCategoryException {
if(line != null){
String[] formattedStringArray = line.trim().split(":");
if(formattedStringArray.length == 2){
throw new DictionaryFormatException();
}

String partOfSpechOfWord = formattedStringArray[0];
String word = formattedStringArray[1];
if(partOfSpechOfWord.equalsIgnoreCase("nouns")){
this.nouns.add(word);
}else if(partOfSpechOfWord.equalsIgnoreCase("verbs")){
this.verbs.add(word);
}else if(partOfSpechOfWord.equalsIgnoreCase("adjectives")){
this.adjectives.add(word);
}else if(partOfSpechOfWord.equalsIgnoreCase("adverbs")){
this.adverbs.add(word);
}else if(partOfSpechOfWord.equalsIgnoreCase("pronouns")){
this.pronouns.add(word);
}else if(partOfSpechOfWord.equalsIgnoreCase("interjections")){
this.interjections.add(word);
}else{
throw new UnsupportedCategoryException();
}
}
}

public String getWord( String partOfSpeech ) throws EmptyWordListException, UnsupportedCategoryException{
String wordToReturn = null ;
if(partOfSpeech.equalsIgnoreCase("nouns")){
if(!checkListIfEmpty(nouns))
wordToReturn = this.nouns.remove(ThreadLocalRandom.current().nextInt(0, nouns.size()));
else
throw new EmptyWordListException() ;
}else if(partOfSpeech.equalsIgnoreCase("verbs")){
if(!checkListIfEmpty(verbs))
return this.verbs.remove(ThreadLocalRandom.current().nextInt(0, verbs.size()));
else
throw new EmptyWordListException() ;
}else if(partOfSpeech.equalsIgnoreCase("adjectives")){
if(!checkListIfEmpty(adjectives))
return this.adjectives.remove(ThreadLocalRandom.current().nextInt(0, adjectives.size()));
else
throw new EmptyWordListException() ;
}else if(partOfSpeech.equalsIgnoreCase("adverbs")){
if(!checkListIfEmpty(adverbs))
return this.adverbs.remove(ThreadLocalRandom.current().nextInt(0, adverbs.size()));
else
throw new EmptyWordListException() ;
}else if(partOfSpeech.equalsIgnoreCase("pronouns")){
if(!checkListIfEmpty(pronouns))
return this.pronouns.remove(ThreadLocalRandom.current().nextInt(0, pronouns.size()));
else
throw new EmptyWordListException() ;
}else if(partOfSpeech.equalsIgnoreCase("interjections")){
if(!checkListIfEmpty(interjections))
return this.interjections.remove(ThreadLocalRandom.current().nextInt(0, interjections.size()));
else
throw new EmptyWordListException() ;
}else{
throw new UnsupportedCategoryException();
}
return wordToReturn;
}

private boolean checkListIfEmpty(List<String> inputList){
return inputList != null ? inputList.isEmpty() : true ;
}

}

Exception Classes:

public class DictionaryFormatException extends Exception {
public DictionaryFormatException () {
super();
}
}

public class EmptyWordListException extends Exception {
public EmptyWordListException () {
super();
}
}

public class UnsupportedCategoryException extends Exception {
public UnsupportedCategoryException () {
super();
}
}

Template.java

public class Template {

private String template;

public Template(String template) {
String bufferString = template.trim().replaceAll("\s+", " ");
this.template = bufferString.split("/")[1].trim();
}

public String fill (Dictonary dictonary) {
return "";
}
}

Please specify clearly the fill() method implementation. The implementation will be completed once the clarification is done.

Driver.java

The loadDictonary() implementation is also not clear. Please provide some information on how to fabricate the raw data to Dictonary object. The implementation will be completed once the clarification is done.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Driver {

public Template loadTemplate ( String fileName ){
String currentLine ;
String templateArg ="";
try(BufferedReader reader = new BufferedReader(new FileReader(fileName))){
while((currentLine = reader.readLine()) != null){
templateArg+=currentLine;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Template template = new Template(templateArg);
return template;
}

public Dictonary loadDictonary( String fileName){
Dictonary dictonary = new Dictonary();
String currentLine ;
String templateArg ="";
try(BufferedReader reader = new BufferedReader(new FileReader(fileName))){
while((currentLine = reader.readLine()) != null){
templateArg+=currentLine;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dictonary;
}
public static void main(String []args){
  
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote