Question
/** This method will ask user for a file name, create an array, and store the integers read from the file into the array If
/** 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 int[] inputData() throws Exception { Scanner keyboard = new Scanner(System.in); System.out.println("Please enter a file name: "); String inputFile = keyboard.next(); File file = new File(inputFile);
if (!file.exists()) { System.out.println("This file does not exist!"); System.exit(0); }
/** This method will computer and reutrn the average of all elements in the array. */ public static double average(int[] array) { double total = 0; double average; for (int i = 0; i
/** This method will find and return the largest value in the array. */ public static int max(int[] array) { int highest = array[0]; for (int i = 1; i highest) highest = array[i]; } return highest; } /** This method should find and return the smallest value in the array. */ public static int min(int[] array) { int lowest = array[0]; for (int i = 1; i 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 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 input Data 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 print Array (int array) -This method will display the content of the array on screen. Print 10 integers per line public static double average (int 1 array) This method should compute and return the average of all elements in the array. public static int max (int 1 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 selection Sort (int array) This method should implement Selection Sort and sort the array of integers into ascending order
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started