Sale!

Java program that reads in a filename from keyboard

$30.00

Category:
Rate this product

Introduction to Computer Science: Project #4 (50 points)

Write a Java program that reads in a filename from keyboard. The file contains integers representing everyday’s temperature in a month. The first line of the input file will contain the number of days in a month. You then create a corresponding array and fill the array with integers from the remaining lines. If the input file does not exist, give an appropriate error message and terminate the program. After integers are stored in an array, your program should call the following methods, output the intermediate results and at end output the monthly highest, lowest, and average temperatures (average represented as double value but displays only 1 digit after the decimal point such as 32.5)
Note: Only main method can display the intermediate results by calling printArray method or using print/println methods. Other methods cannot display results (except inputData method can display an error message when file doesn’t exist.)

Implement the following methods in the program: (note: you must use a method for each of the following task but may change the format/definition of the methods)
• public static int[] inputData() – This method will ask user for a file name, create an array, and store the integers read from the file into the array. If input file does not exist, give an appropriate error message and terminate the program.
• public static void printArray(int[] array) – This method will display the content of the array on screen. Print 10 integers per line.
• public static double average(int[] array) – This method should compute and return the average of all elements in the array.
• public static int max(int[] array) – This method should find and return the largest value in the array.
• public static int min(int[] array) – This method should find and return the smallest value in the array.
• public static void selectionSort (int[] array) – This method should implement Selection Sort and sort the array of integers into ascending order.

A sample run:
$ cat MonthOf12Days.dat
12
60 52 28 32 34 43 44 51 78 28 30 75

$ java ArrayProcessing
enter input filename: MonthOf12Days.dat
original array:
60 52 28 32 34 43 44 51 78 28
30 75
The average temperature is: 46.3F degrees
The highest temperature is 78F degrees
The lowest temperature is 28F degrees
sorted array:
28 28 30 32 34 43 44 51 52 60
75 78

Testing and submit requirements: run the program at least three times, one with a wrong file name, one with the MonthOf12Days.dat as shown above, the other with at least 30 data values (create the data file by yourself.) Create a script file to capture all test runs and zip java file and script file for submission on blackboard.

Open chat
Need help?
Hello
Can we help you?