Create and prompt the user for the name of should be

Assignment Help Computer Engineering
Reference no: EM132170701

(using Java and Netbeans)

Assignment

Write a complete Java program called CalcWeightedAvgDropLowest according to the following guidelines.

For this program, instead of getting the data from the user via System.in, get only the name of the input file - which you should hard-code to "data.txt".

See Horstmann's program Total.java in Section 7.1, pp. 319, 320, on which this assignment is based.

For our program, you should create the data.txt file ahead of time (see below) and then prompt the user for the name of the input file, telling the user that the name of the input file should be "data.txt".

Note that the methods for getting the input from a file and writing the output to a file will need to handle exceptions, whereas in Horstmann's Total.java example, only the main method needs to handle exceptions.

Input File

The input file - which you need to create and prompt the user for the name of - should be called 'data.txt', and it should be created according to the instructions below.

The input file should contain (in order): the weight (greater than 0 and less than or equal to 1), the number, n, of lowest numbers to drop, and the numbers to be averaged after dropping the lowest n values.

For example, you might have these values in your input file (data.txt):

0.5 3 10 70 90 80 20

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 in the projects tab at the upper left. Then starting with the NetBeans File menu, do

File->New File Keep the Project name at the top; keep Filter blank For Categories choose Other (at the bottom of the categories list) For File Types choose 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 one in 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. Then save this data.txt input file.

It's important that your input file is where NetBeans will look to find it. The above instructions should make sure that that happens.

Main method

Your main method should include methods to get the data, to calculate the weighted average, and to print the results. In the method that prints the results, you should prompt the user for the name of an output file and print the results to that output file.

Output

Given the sample values above in the data.txt input file, the output file should contain something very much 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.

Prompting for names of input file and output file

Make sure you prompt the user for the name of the input file (even though we know what it is). You can use a prompt like: "Enter "data.txt" (no quotes) for the name of the input file: "

Also prompt the user for the name of the output file. If you use code like that in Horstmann's Total.java program to create the output file, the output file should be located at the same place as the input file. Check the NetBeans Files tab (next to the Project tab in the upper left) to see both the input and output files.

Reference no: EM132170701

Questions Cloud

Write a program with a data array that has data for company : Using JAVA: Write a program with a data array that has data for one company, one International Company, and one TerritoryCompany.
Write the code for a singly-linked list : Write the code for a singly-linked list that supports the following: (Please note which examples would be more/less efficient with an array implementation)
Madrigal electromotive gmbh buy advertising : Should Madrigal Electromotive GmbH buy this advertising? Why or Why not?
Write a program for the game towers of hanoi : Write a program for the game "Towers of Hanoi", using four pegs, which uses most minimum amount of comparisons to win.
Create and prompt the user for the name of should be : Create and prompt the user for the name of - should be called 'data.txt', and it should be created according to the instructions below.
Issue of contention among foreign : The value of the U.S. dollar relative to the value of other major currencies has always been an issue of contention among foreign exchange experts
Calculate the daily average distance walked by the user : Using Java, how can I use a loop that runs 7 times (using the final variable) to ask and get how many steps the user walks each day of the seven days.
Effects or impacts of globalisation on developing countries : GSP4002 - Business in a Global Context - PATCHWORK PORTFOLIO - Analyse the effects or impacts of globalisation on developing countries
How to do inverse demand in business economics : How to do inverse demand in business economics? The break down of marginal cost, marginal revenue within the supply and demand curve.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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