Starting from:

$15

Program 6 -ArrayProcessing Solution

Write a Java program titled "YourLastName_ArrayProcessing" that reads a file name from the keyboard. If the input file given by the user does not exist, give an appropriate error message and terminate the program. Otherwise the first line of the file will represent the number of lines remaining in the file. You will then create a corresponding array and fill the array with integers from the remaining lines. After integers are stored in your program's array the methods listed below will be called in order, the results of the methods will be printed to the screen, and at the end all results with even integers will be written to a file titled "even.out" and results with odd integers will be written to a file titled "odd.out".
Implement the following methods in the program:
 public static int[] inputData() – this method will ask the user for a file and read in the file location, if the input file does not exist it will give an appropriate error message and terminate the program. Otherwise, it will create an array and store the integers from the file in the array.
 public static void printArray(int[] array) – this method prints out the passed in array to the screen with 10 integers per line, and uses the printf method to align the data in columns.
 public static void reverseArray(int[] array) – this method prints out the passed in array in reverse order to the screen, and uses the printf method to align the data in columns.
 public static int sum(int[] array) – this method computes and returns the sum of the passed in array.
 public static double mean(int[] array) – this method computes and returns the mean of the passed in array.
 public static int min(int[] array) – this method computes and returns the minimum of the passed in array.
 public static int max(int[] array) – this method computes and returns the maximum of the passed in array.
 public static void evenOdd(int[] array) – this method will create the output files "even.out" and "odd.out", scan through the passed in array and if an element is even write it to the even.out file, otherwise write it to the odd.out file.
For example:
The following shows an example interaction captured in a file by the command “% script ArrayProcessing.out” (bolded areas represent the user's input):
Assume the following example input file is used:
20
45
-10
-22
22
86
69
89
83
79
-73
-32
94
72
-33
-80
8
89
-10
-33
52
Script started on Thu Sep 26 10:23:58 2013
% java Diaz_ ArrayProcessing
Please enter a file name: inputFile.dat
Printing Array:
45 -10 -22 22 86 69 89 83 79 -73
-32 94 72 -33 -80 8 89 -10 -33 52
Printing Reversed Array:
52 -33 -10 89 8 -80 -33 72 94 -32
-73 79 83 89 69 86 22 -22 -10 45
The sum of all elements is: 495
The mean of all elements is: 24.75
The minimum of all elements is: -80
The maximum of all elements is: 94
Program completed, remember to inspect 'even.out' and 'odd.out' files.
% exit
script done on Thu Sep 26 10:24:17 2013
The even.out and odd.out files should appear as follows:
The even.out file:
-10
-22
22
86
-32
94
72
-80
8
-10
52
The odd.out file:
45
69
89
83
79
-73
-33
89
-33
Run the program with all different input files provided and capture all interaction in a file using the script command.
What to turn in:
- Soft copy of the results using the script command
- Soft copy of the program (the .java file submitted to Blackboard)

More products