Write the output to a file with that user-supplied name

Assignment Help JAVA Programming
Reference no: EM131596775

Assignment

Create a program called CalcWeightedAvgWithExceptions, and use try-catch-finally blocks in your methods, as in the examples try-catch-finally examples from the class notes for this lesson, which are also shown in the file 'TryCatchFinally.txt' available in this module.

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. Also, your program should include methods for getting the input from the data.txt file, calculating the weighted average according to the data in the data.txt file, and printing the results to a user-designated output file.

Your main method should contain just three lines like these:
ArrayList<Double> inputValues = getData();
double weightedAvg = calcWeightedAvg(inputValues);
printResults(inputValues, weightedAvg);

The inputValues come from a single line in your data.txt file like the following:
0.5 3 10 70 90 80 20

The output file should contain something like the following:
"The weighted average of the numbers is 42.5, when using the data 10.0, 70.0, 90.0, 80.0, 20.0, where 0.5 is the weight used, and the average is computed after dropping the lowest 3 values."
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

In the empty file data.txt that you just created, add a single line of data like the example above, where the weight is a double (greater than 0.0 and less than or equal to 1.0) and the other numbers are the number, n, of lowest values to drop and then the numbers to be averaged after dropping the lowest n values. Also, instead of displaying the output to the console, let the user choose a file name (as in Horstmann's example), and write the output to a file with that user-supplied name (e.g., output.txt).

Reference no: EM131596775

Questions Cloud

What is dollar amount of amortization for june : On December 31, 2016, Happy Corporation issued $560,000, 14%, What is dollar amount of amortization for June 30, 2017
Provide the accounting entries to record the sale : Provide the accounting entries to record the sale, and the subsequent return of the assets, assuming that the returns occur in accordance with expectations
Evidence-based practice project : Provide an initial reference list of a minimum of five resources your CLC group has consulted during the selection process.
Discuss the electronic medical record technology : Develop a 5- to 7-slide presentation that addresses the requirements for a project governance board investigating the feasibility.
Write the output to a file with that user-supplied name : Create a program called CalcWeightedAvgWithExceptions, and use try-catch-finally blocks - write the output to a file with that user-supplied name
What is the amount of the first year''s interest payment : On January 1, Bank, Rupp & Baroque, Inc. issued $50,000 worth of 10minus -year, 9% bonds for $48,890. What is the amount of the first year's interest payment
Discuss environmental management as a competitive advantage : Discussion: Sustainable Development and the Environment. In a blog post to key stakeholders, discuss using environmental management as a competitive advantage.
Create a binary search tree class : CS501 - Advanced Structured Programming and Algorithms Homework - Create a binary search tree class and You MUST use the pseudocodes given in the class
How much cash dividend was paid to preferred shareholders : Out of Africa, a multi-national corporation had a very successful year. How much of the cash dividend was paid to the PREFERRED shareholders

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create a swing based java gui application

COIT11134 - Object Oriented Programming(T12017) This assignment is designed to test the ability in defining superclass, subclasses and creating & using objects in addition to designing Graphical User Interface (GUI).

  Implement the interface map

Define the interface Map. A class that realizes Map has to save the key-value association. In our case, we need a Map to contain identical keys

  Write a class called trafficviolations

Write a Java program that can be used to calculate and notify violators of the fines and/consequences for road traffic breaches as shown in the schedule

  Identify the key properties of a web crawler

Identify the key properties of a web crawler. Describe in detail how each of these properties is implemented in your code.

  Write a java program that demonstrates exception handling

For this project, you will write a Java program that demonstrates exception handling. Your program will accept from the user ten values and place those numbers in an array

  Create a simple java program that connects to database

create a simple Java program that connects to this database using JDBC. Your program should then query this database's "student" table.

  Write a program deal that takes an integer and prints

Write a program Deal that takes an integer, save it in "kHands" from the keyboard and prints kHands poker hands (five cards each hand) from a shuffled deck, separated by blank lines Screenshot of the program and hands.

  What will be the value of x

Consider the following loop which is an inefficient (at best) attempt to increment count 200 times - What will be the value of x after the following code is exe

  Modify the given java application using netbeans ide

Modify the Week Two Java application using NetBeans IDE to meet these additional and changed business requirements: The company has recently changed its total annual compensation policy to improve sales.

  Creates a professorraing class

Write a program that creates a professorRaing class consisting of professor ID and three ratings. The three ratings are used to evaluate easiness, helpfullness, and clarity. In a separate implementation class, allow the user to enter the values.

  Object oriented programming-getting started with classes

Suppose you are car shopping and want to store information about possible choices. Model, and implement an automobile class. Use a UML drawing tool such as Umbrello or Microsoft Visio to create a class diagram. Your class should have at least cons..

  A class is a blueprint for an object

A class is a blueprint for an object. A class may have a default constructor, a constructor with arguments, accessor methods, mutator methods, public fields, and private fields.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd