Question: Hi i need help with adding the statistics part to this question and would appreciate help figuring it out. Write a program that will write

Hi i need help with adding the statistics part to this question and would appreciate help figuring it out.

Write a program that will write 5000 random number to a file named RandomNumbers.txt. Then, read this file and do the following:

Write the even number to a file named EvenNumbers.txt

Write the odd number to a file named OddNumbers.txt

Write the following statistics to the file named Stats.txt

Largest number in RandomNumbers.txt

Smallest number in RandomNumbers.txt

The average of all the values in RandomNumbers.txt

Number of even values

Number of odd values

MY CODE IS BELOW, THE ONLY PART I NEED TO ADD IS WRITING THE STATISTICS TO STAT.TXT

import java.util.*; import java.io.*; public class FilesQuestion3{ public static void main(String [] args)throws IOException { int large = 0; int num; PrintWriter out = new PrintWriter(new File("random.txt")); Random rand = new Random(); int number, count=0, count2=0; while(count<5000) { while(count2<15) { number=rand.nextInt(5000)+1; out.print(number); count++; count2++; } count2 = 0; out.println(); } out.close(); int i; try{ FileOutputStream fodd = new FileOutputStream("dataodd.txt"); FileInputStream fin = new FileInputStream("random.txt"); FileOutputStream feven = new FileOutputStream("dataeven.txt"); while((i=fin.read()) != -1) { if(i%2==0) feven.write(i); else fodd.write(i); } fodd.close(); fin.close(); feven.close(); }catch(Exception e){ } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!