Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Business Economics Expert

Is to write a program (project) that asks the user to specify an input file and output file. Have the program read each number in the input file to calculate the average of all of the numbers. Then write that number to the output file along with "<== average".

To be clear - if the input file contained the numbers 5, 12, 3, 4 then the output file would only contain:

6.0 <== average

This is my assignment, right now I have my java code taking the smallest number of the file instead of the average number. What do I change it to to get the average of the numbers in the specified file?

Code:

import java.io.File;

import java.io.FileNotFoundException;

import java.io.PrintWriter;

import java.util.Scanner;

public class FindAverage {

   public static void main(String[] args) throws FileNotFoundException {

       Scanner input = new Scanner(System.in);

  System.out.print("Please Enter the input file name: ");

  String inputFile = input.nextLine();

  File file = new File(inputFile);

   Scanner fileRead = new Scanner(file);

   double vals = Double.valueOf(fileRead.nextLine());

   while (fileRead.hasNextLine()) {

                double num = Double.valueOf(fileRead.nextLine());

                if( vals < num) {

                           vals = num;

                       } else {

                       }

            }

   System.out.println("Please Enter the output file name : ");

    String outputFile = input.nextLine();

    File fileout = new File(outputFile);

    PrintWriter pw = new PrintWriter(outputFile);

    pw.write(vals +" <== smallest number");

    pw.close();

  }

  }

Business Economics, Economics

  • Category:- Business Economics
  • Reference No.:- M93086459
  • Price:- $10

Priced at Now at $10, Verified Solution

Have any Question?


Related Questions in Business Economics

In your opinion if the government imposes unit sales tax ie

In your opinion, if the government imposes unit sales tax (i.e. $ tax per unit sold) on a product, will the market equilibrium change? Which one, demand or supply will shift? Increase or decrease? Will new tax cause "dis ...

You are the sales manager supervising a sales force of

You are the sales manager supervising a sales force of three in a kitchen appliance department. You are considering changing the compensation and would like to know if there is a significant difference in sales among the ...

In a survey of 3439 adults 1418 say they have started

In a survey of 3439 adults, 1418 say they have started paying bills online in the last year. Construct a? 99% confidence interval for the population proportion. Interpret the results.

Why is the term asymmetric information in order to

Why is the term asymmetric information in order to understand why some people are better informed than others, and the imbalance in information affects the choices they make and how they deal with one another?

A forced-choice design is often used to compare the

A forced-choice design is often used to compare the attractiveness of pheromones to insects. A Y-tube is used. The pheromone is place on one branch; the control on the second branch; and the insect on the third branch. T ...

An article describes a study that appeared in the journal

An article describes a study that appeared in the journal Pediatrics. In this study, researchers looked at records of 2500 children who were participating in a long term health study. They found that 10% of these childre ...

Suppose a bond with no expiration date has a face value of

Suppose a bond with no expiration date has a face value of $10,000 and annually pays a fixed amount of interest of $900. a. In the table provided below, calculate and enter either the interest rate that the bond would yi ...

On average the parts from a supplier have a mean of 358

On average, the parts from a supplier have a mean of 35.8 inches and a standard deviation of 2.4 inches. Find the probability that a randomly selected part from this supplier will have a value between 31.0 and 40.6 inche ...

The price of cell phones rose slightly higher from 50000 to

The price of cell phones rose slightly higher from $500.00 to $550.00 this past month, and Samsung found out about Apple's release of the iPhone X, so in turn it decided to increase production of its Galaxy S8 from 150,0 ...

What are the assumptions of linear regression analysis and

What are the assumptions of linear regression analysis and, How do we interpret the regression coefficients ,can u give a real life example of how linear regression is used in statistical research

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As