Question: Copyable Java Text: public class Madlibs { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print(Enter template filename:); String templateName = in.nextLine().trim();

 Copyable Java Text: public class Madlibs { public static void main(String[]

args) { Scanner in = new Scanner(System.in); System.out.print("Enter template filename:"); String templateName

= in.nextLine().trim(); System.out.print("Enter dictionary filename:"); String dictionaryName = in.nextLine().trim(); System.out.print("Enter output filename:");

String outputName = in.nextLine().trim(); Template t = loadTemplate(templateName); Dictionary d = loadDictionary(dictionaryName);

try { PrintWriter out = new PrintWriter(outputName); out.println(t.fill(d)); out.close(); } catch(Exception e)

{ System.out.println("Cannot write to file: '" + outputName + "'"); } in.close();

Copyable Java Text:

public class Madlibs {

public static void main(String[] args) { Scanner in = new Scanner(System.in);

System.out.print("Enter template filename:"); String templateName = in.nextLine().trim(); System.out.print("Enter dictionary filename:"); String dictionaryName = in.nextLine().trim(); System.out.print("Enter output filename:"); String outputName = in.nextLine().trim();

Template t = loadTemplate(templateName); Dictionary d = loadDictionary(dictionaryName);

try { PrintWriter out = new PrintWriter(outputName); out.println(t.fill(d)); out.close(); } catch(Exception e) { System.out.println("Cannot write to file: '" + outputName + "'"); }

in.close(); }

static private Dictionary loadDictionary(String fileName) { // TODO }

static private Template loadTemplate(String fileName) { Template t;

try { Scanner in = new Scanner(new FileReader(fileName)); t = new Template(in.nextLine()); in.close(); } catch (Exception e) { System.out.println("Cannot open file: '" + fileName + "'"); t = new Template(""); }

return t; } } class DictionaryFormatException extends RuntimeException { DictionaryFormatException(String badEntry) { super("[Error]: Invalid dictionary entry: '" + badEntry + "'"); } } class UnsupportedCategoryException extends RuntimeException { UnsupportedCategoryException(String badCategory) { super("[Error]: Unsupported category: '" + badCategory + "'"); } } class EmptyWordListException extends RuntimeException { EmptyWordListException(String badCategory) { super("[Error]: No remaining words of category: '" + badCategory + "'"); } }

class Template { // TODO } class Dictionary { // TODO }

1 Overview In this assignment, you will be generating MadLibs based on templates and word lists stored in files. This assignment focuses on file input/output and exception handling (throwing and catching) 2 Requirements You should implement the following classes according to the UML diagrams. Be sure to include a small comment for at least each 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. DictionaryFormatExceptiorn 2. EmptyWordListException 3. UnsupportedCategoryException 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 method throws an UnsupportedCategoryException if the part of speech does not

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!