Question: 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

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!