Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java. Only use FileWriter/PrintWriter. Don't use BufferedWriter In this lab, we are going to explore File IO (Input/Output) with Java as well as handling exceptions

java. Only use FileWriter/PrintWriter. Don't use BufferedWriter

image text in transcribed

image text in transcribed

image text in transcribed

In this lab, we are going to explore File IO (Input/Output) with Java as well as handling exceptions with try-catch blocks. We will do this by using a random number generator from the Random object. Your job is to create a project in Eclipse called lab2 and a class FileI0 in the corresponding src folder. Make sure to click the box to include the main() method when creating the class. Once created, you must edit your class to complete the following steps in order: - Take an integer N input from the user via the keyboard. - Create a file (through the code) named "numbers.txt". - Write N random integers (between 1 and 100) to the numbers.txt file. - Close the "numbers.txt" file. - Create an integer array of size N. - Read the numbers from the "numbers.txt file and store them in the integer array. Append the numbers, formatted as an array (see example output), to the "numbers.txt file with a header "Numbers:. - Sort the array using the Arrays.sort() method. - Append the sorted numbers, formatted as an array (see example output) to the numbers.txt file with a header "Sorted Numbers:". - Find the number of Odd and Even numbers in the array. - Append the number of Odd and Even numbers to the numbers.txt file. - Find the smallest and largest number in the array. - Append the smallest and largest number to the "numbers.txt" file. - Find the mean value of the array. Append the mean value with two decimal places to the numbers.txt file. - Close the "numbers.txt" file. Hints: Don't forget to close your Scanners and Files when you are done using them! Remember what we discussed in class about using FileWriter and Print Writer for appending. Also, be specific with your try-catch exception handling. Note: you must include comments detailing each major line/step of the code (approximately a sentence each) so that we can follow your code easily. Also, make sure your output format looks exactly like the test run's output (of course you cannot replicate the numbers as they are random). Test Run: Console: Enter an integer to generate N random numbers: 7 numbers.txt": 76 62 30 11 89 8 7 OOM Numbers: [76, 62, 30, 11, 89, 8, 7] Sorted Numbers: [7,8, 11, 30, 62, 76, 89] Number of odd numbers: 3 Number of even numbers: 4 Smallest number: 7 Largest number: 89 Mean: 40.43 Rubric: Task Take input from the keyboard Create the numbers.txt file Write N random integers to the numbers.txt file Read integers from the numbers.txt file into an integer array Close the numbers.txt file before reusing it Append the formatted array of integers to the numbers.txt file Append the formatted sorted array of integers to the numbers.txt file Append the number of odd and even numbers to the numbers.txt file Append the smallest and largest number to the numbers.txt file Append the mean value to the numbers.txt file Close the numbers.txt file and any scanners Output follows the sample output format Program is well commented

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

Define Management or What is Management?

Answered: 1 week ago

Question

What do you understand by MBO?

Answered: 1 week ago

Question

What is meant by planning or define planning?

Answered: 1 week ago