Answered You can hire a professional tutor to get the answer.

QUESTION

Project Five The Temperature Statistics Problem Write a program to produce the statistics for temperatures stored in a file.

Project Five The Temperature Statistics Problem Write a program to produce the statistics for temperatures stored in a file. The centigrade temperatures in the file are the monthly averages for 12 months (January to December) in Cuba.

Here is a sample displaying the required report:

Temperature Statistics in Centigrade

--------------------------------------

Average Temperature: 25.22

High Temperature: August 27.80

Low Temperature: January 22.20

Temperature Statistics in Fahrenheit

--------------------------------------

Average Temperature: 77.39

High Temperature: August 82.04

Low Temperature: January 71.96

Part I main Driver - TempDriver main should follow this sequence: 1. Declare an array of 12 doubles.

2. Declare a string with a value like this.

It is the path where the temp.dat file is stored. String filePath = "e:\temp.dat"; This temp.dat file is included with the assignment. Download and save the file on a storage device. You may need to change the drive designation in the string, depending on where you store the file. Windows 10 requires that a file be in a folder so this may be the path: c:\folder\temp.dat Mac Users (file path)  Use the forward slash to separate directories instead of the back slash.  Enter something like this if the file is on the desktop: /Users/Name/Desktop/temp.dat  The directory name and file name are case sensitive so you must use a capital letter where applicable.

3. Call the readFile method that is part of the main driver file.

The readFile method receives the file path string and an array from main, and reads the file data into the array. Use the FileIO file in the Chapter Seven materials as an example of reading file data into an array. The FileArrayExcept file in the Chapter Ten materials is an example of displaying possible error messages.

Display an error message if the file is not found and add this statement after displaying the error message: System.exit(-1); Here is the structure of TempDriver before adding the Temp class code.

Class - Temp Write a class to perform the statistics for any array of 12 temperatures. The Temp Class -

Be sure to write and test one method at a time. Copy/paste the months array at the top of the class with the other private declarations. private String [] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

Temp has these instance variables in the constructor:

double arr[] will be assigned the array values passed to it from main.

double avg = assign 0

int maxIndex = assign 0

int minIndex = assign 0

Temp contains these methods.

 calcAvg method calculates the average of the values in arr, sets avg equal to the result, and returns the average, which is a double.

 findMax method finds the maximum value in arr and its index in the array. maxIndex in the constructor is set to the index of the maximum value. The method returns the maximum value, which is a double. Write the code assuming the values are not in ascending order. Do not sort the values.

 findMin method finds the minimum value in arr and its index in the array. minIndex in the constructor is set to the index of the minimum. The method returns the minimum value, which is a double. Write the code assuming the values are not in ascending order. Do not sort the values

.  convertToFah uses the array (arr) in the constructor to convert the Centigrade values to Fahrenheit. Use a for loop to adjust the values in arr. The formula for converting Centigrade to Fahrenheit is Fahrenheit = Centigrade * 9.0/5.0 + 32; You will need to use this method before displaying the temperatures in Fahrenheit.

Page 4  toString method creates the output string using the instance variables in the constructor: See page 1 for the required output.

Use DecimalFormat (Chapter Three) to display 2 decimals. Here is how you should approach the code in the Temp class. o Declare the instance variables. o Code the constructor. o Add the appropriate code to main. o

Add a for loop in the constructor to display the array arr to see that the values are correct. o Do not add any more code until the arr array contains the correct values. o Code the calcAvg method. o Create the code in toString to display just the average until it works correctly. o Add the appropriate code to main. o Code the findMax method. o Do not code findMin until findMax works. o Code the convertToFah method. All names in bold must be used as specified.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question