Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Be sure to document the added source code with comments and format it appropriately. 1 . Complete the code for the getMenuData ( ) method

Be sure to document the added source code with comments and format it appropriately.
1. Complete the code for the getMenuData() method so that it opens the file passed in via the fileName parameter. This method should read and parse the data in the text file using a Scanner. The code must include try and catch blocks to handle exceptions that may be thrown while opening or reading data from the file. The code for the getMenuData() method already includes a StringBuilder to assemble the multiline string with formatted data like this:
coffee 8 oz. $1.95
coffee 12 oz. $2.25
coffee 16 oz. $2.60
coffee 20 oz. $2.95
tea 8 oz. $1.75
tea 12 oz. $2.00
tea 16 oz. $2.25
tea 20 oz. $2.50
water 8 oz. $0.99
The method returns the contents of the StringBuilder as a string. Be sure to close the Scanner that reads from the file.
2. Complete the code for the writeMenuText() so that it uses a PrintWriter to write to the File object passed in as the first parameter. The multiline String value to write to the file is passed in at the second parameter. If the file does not already exist, the code for the writeMenuText() method needs to create it. Since an exception could be thrown when creating the file, include appropriate try and catch blocks. The catch block should print out a readable message for the user in the console that indicates the problem (rather than displaying a stack trace). Close the PrintWriter before returning from the method.
The contents of the output file after running the program should look like this:
Beverage Size Price
_________________________
coffee 8 oz. $1.95
coffee 12 oz. $2.25
coffee 16 oz. $2.60
coffee 20 oz. $2.95
tea 8 oz. $1.75
tea 12 oz. $2.00
tea 16 oz. $2.25
tea 20 oz. $2.50
water 8 oz. $0.99
3. After the code for the getMenuData() and writeMenuText() is complete, write the code for the main() method so that it produces output like this in the NetBeans console by calling the getMenuData() and writeMenuText() methods.

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

What does this key public know about this issue?

Answered: 1 week ago

Question

What is the nature and type of each key public?

Answered: 1 week ago

Question

What does this public need on this issue?

Answered: 1 week ago