Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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();

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions