Question

I am confused on how to read valid lines from the input file. I am also...


I am confused on how to read valid lines from the input file. I am also confused on how to count the averages from these valid input lines to keep running the total from these valid lines. If you could show an example of an input and output file that would be amazing as well.

Purpose        Learn how to use Java input/output.

Due Date       Per the Course at a Glance. Can be resubmitted.

Submissions           In this order: printed copy of the source code with line numbers, copy of the input file, and a copy of the output file. If you are handing in a revision, hand in the original graded version(s) and put the newer revised version on top.

Java Topics Java I/O, while loop, summing for a total and average.

References   Textbook – use the index for relevant topics.

Specification

This program uses files for input and output and is based on the File Input/Output Example program discussed in class and included in FLIP_FILES.zip.

The names of the input and output files should be, respectively:

            YourName_S_04_Input.txt

            YourName_S_04_Output.txt

Using jGrasp | File | New | Plain Text or Notepad on a PC or TextEdit on a Mac, create an input text file which contains the information below. (On the Mac, use the TextEdit feature that saves files as .txt files, not .rtf files.). The input file has this information in order of gross pay, savings percentage rate and IRA investment rate:

     100.00   10.0 5.0

        1000.00   11     6

     1000.00   11    -6

   1234.56      10.5   6.0

6543.21    10    5.0

     10000       12    10

     -1000   10.00   5.00

   4444.22    10.2    4.9

      2222.44        11.9    10

      3141.59      12    5.0

Insert code that calculates the savings amount and the IRA investment amount from the numbers for valid lines that are read from the input file. You will also calculate the averages of the gross pay, savings amount and investment amount for all input lines that are valid. Valid input lines have numbers greater than 0 for all three input numbers. To calculate the averages, you’ll need to count the number of input lines, number of valid input lines and keep running totals. Output the numbers read and the calculated amounts to the output file and to the console in tabular form. Here is an example using the numbers above. Note that dollar amounts should be output to two decimal places and percentage rates to one decimal place.

Gross Pay   Savings Rate Savings Amount IRA Rate IRA Amount

     100.00             10.0                10.00              5.0             5.00

     1000.00            11.0                  110.00          6.0              60.00

etc.

We’ll learn soon how to line up the decimals so the numbers aren’t “ragged.”

After reading all the numbers, output the following to the output file and the screen with appropriate messages:

1.   The total number of input lines read.

2.   The sum of the gross pay, savings amount and IRA amount.

3.   The average of the gross pay, savings amount and IRA amount, where the average is calculated only for valid input lines.

When calculating the average, be sure to check that the denominator is not zero.

Include comments in the header area at the start of the program and that the revision numbers, if any, are noted.

Please staple the sheets and write the usual information at the upper right-hand corner of the page.

I know this is more than one question I really appreciate your time and help.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
I am confused on how to read valid lines from the input file. I am also...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • I am trying to read from a file with with text as follows and I am...

    I am trying to read from a file with with text as follows and I am not sure why my code is not working. DHH-2180 110.25 TOB-6851 -258.45 JNO-1438 375.95 CS 145 Computer Science II IPO-5410 834.15 PWV-5792 793.00 Here is a description of what the class must do: AccountFileIO 1. Create a class called AccountFileIO in the uwstout.cs145.labs.lab02 package. (This is a capital i then a capital o for input/output.) a. This class will read data from a file...

  • 1. write a java program using trees(binary search treee) to read integers from input file( .txt)...

    1. write a java program using trees(binary search treee) to read integers from input file( .txt) and add +1 to each number that you read from the input file. then copy result to another (.txt) file. example: if inpu File has numbers like 4787 79434 4326576 65997 4354 the output file must have result of 4788 79435 4326577 65998 4355 Note: there is no commas in between the numbers. dont give images or theory please.

  • Write a program that will take input from a file of numbers of type double and...

    Write a program that will take input from a file of numbers of type double and output the average of the numbers in the file to the screen. Output the file name and average. Allow the user to process multiple files in one run. Part A use an array to hold the values read from the file modify your average function so that it receives an array as input parameter, averages values in an array and returns the average Part...

  • (Java) Rewrite the following exercise below to read inputs from a file and write the output...

    (Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...

  • I have the files set up in the write place. I am just confused on how...

    I have the files set up in the write place. I am just confused on how to use some of the desire methods to execute this code. // Copy text file and insert line numbers Create a NetBeans project named AddLineNumbers following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans project AddLineNumbers and before you attempt to execute your application download and/or copy the text...

  • I am given an input file, P1input.txt and I have to write code to find the...

    I am given an input file, P1input.txt and I have to write code to find the min and max, as well as prime and perfect numbers from the input file. P1input.txt contains a hundred integers. Why doesn't my code compile properly to show me all the numbers? It just stops and displays usage: C:\> java Project1 P1input.txt 1 30 import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 {    public static...

  • Hello, I need the pseudocode / flowchart for the following : read input from a file...

    Hello, I need the pseudocode / flowchart for the following : read input from a file by adding all the numbers in a file to an array, then iterate through the array to count how many times each number appears in the array (the frequency of each number) - then write the summation results to a file: summary.txt. Need to use a numbers.txt file that looks like this:

  • C++ please Write a program that reads the following sentences from a file: I am Sam...

    C++ please Write a program that reads the following sentences from a file: I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am Do you like green eggs and ham I do not like them But I do like spam! You will first have to create the text file containing the input, separate from your program. Your program should produce two output files: (i) (ii) one with the...

  • In golang: How do I take lines from an input file and sort each individual word...

    In golang: How do I take lines from an input file and sort each individual word into structs?

  • In c language. I have to read 3 files and used the numbers in the file...

    In c language. I have to read 3 files and used the numbers in the file in a program. An example of the 3 files are below. How do read the numbers, I realize it’s with arrays. The input won’t have more than 100 lines but it can have less n 3. Input Files The filename includes the variable name and the sensor number as: variable name <sensor id txt For example "BT 0001.txt" is the file that contains the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT