Create a program called calcweightedavgwithexceptions2 by


Assignment

Create a program called CalcWeightedAvgWithExceptions2 by modifying Horstmann's program DataAnalyzer.java (Section 7.5, pp. 350-351, and also in this module), according to the specifications below. The input file should be called 'data.txt' and should be created according to the highlighted instructions below.

The input file should contain (in order): the weight, the number, n, of lowest numbers to drop, and the numbers to be averaged after dropping the lowest n values. See the example below.

Your program should allow the user to re-enter the input file name if one or more of the exceptions in the catch clauses are caught. You need not, but you may, also allow the user to reenter an output file name if exceptions in opening the output file are caught.

1. Modify the structure of the main method in Horstmann's DataAnalyzer.java so that, in addition to prompting the user to enter 'data.txt' as the name of the input file, you call a method to calculate the weighted average prompt the user for the name of an output file, and then call a method to print the results to the output file.

2. Your methods should handle exceptions in trying to read the input file in a way similar to the way Horstmann handles them in DataAnalyzer.java. Your method for calculating the weighted average need not handle any exceptions (though it may), and how your method for printing the results handles exceptions is up to you.

3. The main focus is to give your program the ability to re-enter the input file name if the specified exceptions are caught.

Creating the Input File
To create the input file, while in NetBeans with your project open, click to highlight the top-level folder of your project, which should be called CalcWeightedAvgWithExceptions. Then:
File-→New File...
Keep the Project name at the top; keep Filter blank
Categories → Other (at the bottom of the categories list)
File Types → Empty File (at the bottom of the files list)
Next>
FileName: data.txt
Folder: this should be blank; if it's not, delete whatever's there
Finish

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a program called calcweightedavgwithexceptions2 by
Reference No:- TGS02392325

Now Priced at $10 (50% Discount)

Recommended (93%)

Rated (4.5/5)