Question

please put the comment each line, make sure i will have output too. write a program,...

please put the comment each line, make sure i will have output too. write a program, Summarize (Summarize.java), containing the main() method, that first writes 10,000 random positive double type numbers, to the full accuracy of the number (15/16 decimal places), to a text file named DataValues.txt, one number per line. The program must then close that file, and reopen it for reading. Read back the values from the file and write the following information to a file named Summary.txt:

Your name;
The class name and section number;
The current date/time (i.e., the date when the Summarize program is being run—which also means that the date/time when the Instructor runs that program should be the date seen);
The total number of values in the file (which should be exactly the number you generated, but count them anyway);
The average of the values in the file (i.e., the sum, divided by the count of numbers);
The largest value in the file; and,
The smallest value in the file (these last three values being shown to 14/15 decimal places).
Please use as your random number generator a Random class object, declared and initialized as follows:

public static final Random random = new Random(-1L);
and using the method nextDouble to get the actual double values.

You may determine the presentation of the information in the output file, but the end result should be clear and easy to read (see sample below).

Please submit at least three files for this part of the homework:

Summarize.java—the program that writes and then reads the text file of values and prints summary information about those values, plus any other subsidiary Java files that your solution may need;
DataValues.txt—the file containing the numbers; and,
Summary.txt—the file containing the summary information.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/***************************************Summarize.java*********************/

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;

public class Summarize {

   public static final Random random = new Random(-1L);

   public static void main(String[] args) {

       double total = 0.0;
       double[] data = new double[10000];
       int count = 0;
       double largest = Double.MIN_VALUE;
       double smallest = Double.MAX_VALUE;
       try {
           FileWriter writer = new FileWriter("DataValues.txt");
           BufferedWriter bw = new BufferedWriter(writer);
           for (int i = 0; i < 10000; i++) {

               bw.write(random.nextDouble() + "\n");
           }

           bw.close();
       } catch (IOException e) {
           System.err.format("IOException: %s%n", e);
       }

       try {

           Scanner scan = new Scanner(new File("DataValues.txt"));
           while (scan.hasNext()) {

               data[count] = scan.nextDouble();
               count++;
           }
           scan.close();
       } catch (FileNotFoundException e) {
           System.err.println(e);
       }

       for (double d : data) {

           total += d;

           if (largest < d) {

               largest = d;
           }
           if (smallest > d) {

               smallest = d;
           }
       }

       double avg = total / count;
       try {

           DecimalFormat format = new DecimalFormat("##.000000000000000");
           FileWriter writer = new FileWriter("Summary.txt");
           BufferedWriter bw = new BufferedWriter(writer);
           bw.write("The class name and section number: ADD HERE\n");//update here
           bw.write("The current date/time: " + new Date() + "\n");
           bw.write("The total number of values in the file: " + count + "\n");
           bw.write("The average of the values in the file: " + format.format(avg) + "\n");
           bw.write("The largest value in the file: " + format.format(largest) + "\n");
           bw.write("The smallest value in the file: " + format.format(smallest) + "\n");
           bw.close();
       } catch (IOException e) {
           System.err.println(e);
       }
   }
}
/*******************output*******************/

The class name and section number: ADD HERE
The current date/time: Sun Nov 17 17:12:19 IST 2019
The total number of values in the file: 10000
The average of the values in the file: .501431425159974
The largest value in the file: .999902254781280
The smallest value in the file: .000021260344885

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
please put the comment each line, make sure i will have output too. write a program,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1.Write a python program that writes a series of random numbers to a file named random.txt....

    1.Write a python program that writes a series of random numbers to a file named random.txt. Each random number should be in the range of 1 through 300. The application should let the user specify how many random numbers the file will hold. 2. Write another program that reads the random numbers from the random.txt file, displays the numbers, then displays the following data: I. The total of the numbers II. The number of random numbers read from the file

  • Write a program that reads a file named input.txt and writes a file that contains the...

    Write a program that reads a file named input.txt and writes a file that contains the same contents, but is named output.txt. The input file will contain more than one line when I test this. Do not use a path name when opening these files. This means the files should be located in the top level folder of the project. Do not use a copy method that is supplied by Java. Your program must read the file line by line...

  • Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that...

    Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...

  • Please use Python for this program Random Number File Writer Write a program that writes a...

    Please use Python for this program Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range 1 through 500. The program should let the user specify how many random numbers to put into the file. The name of the file to write to should be 'random.txt'. Submit the random.txt file generated by your program with the assignment. Sample program execution: Python 3.4.3 Shell Eile Edit...

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

  • Write a program that writes a series of random numbers to a file. Each random number...

    Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500 inclusive. 1.Use a file called randoms.txt as a input file and output file a. If you go to open the file and its not there then ask the user to create the file     and then quit 2. Ask the user to specify how many random numbers the file will hold. a.Make sure that the...

  • Java2 Screenshot of the output required Put some comment This is the mailing text file for...

    Java2 Screenshot of the output required Put some comment This is the mailing text file for the assignment ..Il AT&T令 12:28 AM Back Complete and Submit Lab 2C Detail Submission Grade Complete and Submit Lab 2C Due: Mar 1, 2019 at 11:59 PM In class you learned how to read text from a file using the Scanner class and write text to a file using the Formatter class. This lab allows you to apply the skills you learned about files...

  • please read directions first. this is supposed to be a hybrid programe add comments please JAVA...

    please read directions first. this is supposed to be a hybrid programe add comments please JAVA please add comments Programming Project 1 and Programming Project 2 "Hybrid" Your goal is to write a program that combines the functionality of both Programming Project 1andProgramming Project 2 into a single program. That is, your program should read a file ( Numbers.txt) of numbers of type double that contains some duplicates and is ordered smallest to largest. Your program should ignore the duplicate...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

    Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million. Your program should read the following and display: The number of numbers in the file (i.e. count them) (counter) The maximum number in the file (maximum)...

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