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
  • 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...

  • 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.

  • 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...

  • (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...

  • The program will need to accept two input arguments: the path of the input file and...

    The program will need to accept two input arguments: the path of the input file and the path of the output file. See etc/cpp/example.ifstream.cpp for the basis of how to do this. Once the input and output file paths have been received, the program will need to open the input and output files, read and process each input file line and create a corresponding output file line, close the input and output files, and then create and output some summary...

  • 2. Write a program to read two lists of names from two input files and then...

    2. Write a program to read two lists of names from two input files and then match the names in the two lists using Co-sequential Match based on a single loop. Output the names common to both the lists to an output file, In Java

  • 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...

  • Capitalization JAVA In this program, you will read a file line-by-line. For each line of data...

    Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...

  • I am writing a program in C++, which requires me to read an input text file...

    I am writing a program in C++, which requires me to read an input text file using command line argument. However, I am using xcode on my Macbook to write C++ program, and use terminal instead of command. How do you use int main(int argc, char** argv[]) to read an input file. My professor requires us not to hard code the text file name like .open("example.txt"); Thank you!

  • get names of input and output files from command line (NOT from user input)

     2.12 LAB 2.3: File I/O - CSV update This program shouldget names of input and output files from command line (NOT from user input)read in integers from a csv (comma-separated values) file into a vectorcompute the integer average of all of the valuesconvert each value in the vector to the difference between the original value and the averagewrite the new values into a csv file

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
ADVERTISEMENT