In Java. Write a program in a single file that: Main: Creates 10 random doubles, all between 1 and 11, Calls a class that writes 10 random doubles to a text file, one number per line. Calls a class that reads the text file and displays all the doubles and their sum accurate to two decimal places. There has to be three classes, main for create random numbers, one to write , one to read all in the same file
SAMPLE OUTPUT
10.6269119604172
2.737790338909455
5.427925738865128
1.3742058065472509
1.1858700262498836
4.180391276485228
4.910969998930675
5.710858234343958
7.790857007373052
3.1806714736219543
The total is 47.13
The program runs, the main question I have is. what does my professor mean by "in a single file"
In the below program, all the classes (Writer, Reader and Main) are written in the same file, "Main.java" . You can run the program by running Main class.
CODE :
import java.io.*;
import java.util.Random;
import java.util.Scanner;
class Writer{
public void write(double arr[]) throws IOException {
//Writer to write to file
BufferedWriter writer = new BufferedWriter(new FileWriter(new File("doubles.txt")));
//Iterate through double array
for(int i=0;i<arr.length;i++){
//Write to file
writer.write(String.valueOf(arr[i]));
//Write to next line
if(i!=arr.length-1){
writer.write("\n");
}
}
writer.flush();
writer.close();
}
}
class Reader{
public double getSum() throws IOException {
//Reader to read file
BufferedReader br = new BufferedReader(new FileReader(new File("doubles.txt")));
String str;
double ans = 0;
//Read all lines
while((str=br.readLine())!=null){
//Find sum
ans = ans + Double.parseDouble(str);
}
return ans;
}
}
class Main{
public static void main(String[] args) throws IOException {
Random r = new Random();
double arr[] = new double[10];
//Generate 10 randoms from 1 to 11
for(int i=0;i<10;i++){
arr[i] = 10*r.nextDouble()+1;
System.out.println(arr[i]);
}
Writer w = new Writer();
w.write(arr);
Reader rd = new Reader();
System.out.println("Total is "+rd.getSum());
}
}
OUTPUT :

In Java. Write a program in a single file that: Main: Creates 10 random doubles, all...
please help me with, Write a program in java that generates 10 random doubles, all between 1 and 11, and writes them to a text file, one number per line. Then write another program that reads the text file and displays all the doubles and their sum accurate to two decimal places. SAMPLE OUTPUT 10.6269119604172 2.737790338909455 5.427925738865128 1.3742058065472509 1.1858700262498836 4.180391276485228 4.910969998930675 5.710858234343958 7.790857007373052 3.1806714736219543 The total is 47.13
java question: Write a program that reads in data from a text file named in.txt. Compute the sum of all the valid integers in the input file. Likewise, compute the sum of all the valid doubles in the input file. Write the former to an output file called int_total.txt, and write the latter to an output file called double_total.txt. B) Write a program that converts the Java source code from the next-line brace style to the end-of-line brace style. For...
Write a program in C that creates an array of 100 random numbers from 0-99. The program sums the random numbers and prints the sum. It then writes the numbers to a new file using open, close and write. Then looks in the current directory for files that match the pattern “numbers.XXXX”. For each file, open the file and read the file. You can assume that the file will contain 100 integers. Sum the integers. Print the filename and the sum...
Java. (20 pts) Write a program that reads all the numbers from the file mynums.dat and prints out the sum of the positive values from the file. Assume that the file contains only numeric values. You must output an error if the file can't be opened. You must write the complete program and the output when the program runs successfully must conform exactly to the sample output. Bonus ( 5 pts). Output an error if the file contains non-numeric...
Write a java program that creates a file called numbers.txt that uses the PrintWriter class. Write the odd numbers 1 to 99 into the file. Close the file. Using Scanner, open the numbers.txt file and read in the numbers. Add them all up and print the total. Close the file.
IN JAVA. Write a program that reads a file (provided as attachment to this assignment) and writes the file to a different file with line numbers inserted at the beginning of each line. For example if file input is: This is a test File output should be 1. This is a test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ BELOW FROM NOTEPAD FILE. This file contains lines of text to determine if you can properly read and write from a file.
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 Java program that reads words from a text file and displays all the non-duplicate words in ascending order. The text file is passed as a command-line argument. Command line argument: test2001.txt Correct output: Words in ascending order... 1mango Salami apple banana boat zebra
Write a program using Java Streams that reads an arbitrary text file and creates pairs from everything it finds in the file that is a number and the word that precedes that number. Example input: I need to buy 5 notebooks and 4 folders in 2 days for school. Output. buy 5 and 4 in 2
Write a java program that declares 10 element array (of type integers), creates and initializes the array, and perform the sum of elements of the array using for loop. public class SumArray { public static void main (String[], args) { } // end of main } // end of SumArray class