Question

In: Computer Science

Write a program that uses an array of high temperatures for your hometown from last week...

Write a program that uses an array of high temperatures for your hometown from last week (Sunday – Saturday). Write methods to calculate and return the lowest high temperature (minimum) and a method to calculate and return the highest high temperature (maximum) in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods.

Write an additional method that accepts the array as a parameter and then creates and returns a new array with all the same values as the original plus 10. (num +=10)

Your output should be formatted in such a way that it makes sense for what a user would want to see. Remember to output a description of what you are showing the user - not just values on a screen.

Submit all your .java files, .class files and screenshots of your code and output.

Solutions

Expert Solution

Source Code in Java:

class Temperatures
{
static int max(int temps[]) //method to calculate and return maximum of an array
{
int max=temps[0]; //temporary maximum
for(int i=1;i<temps.length;i++)
{
if(temps[i]>max)
max=temps[i];
}
return max; //returning maximum
}
static int min(int temps[]) //method to calculate and return minimum of an array
{
int min=temps[0]; //temporary minimum
for(int i=1;i<temps.length;i++)
{
if(temps[i]<min)
min=temps[i];
}
return min; //returning minimum
}
static int[] increase(int temps[]) //method to increase every element of an array by 10 and return it
{
int incTemps[]=new int[temps.length]; //creating new array
for(int i=0;i<temps.length;i++)
incTemps[i]=temps[i]+10; //filling new array with increased values
return incTemps; //returning new array
}
public static void main(String args[])
{
//testing the functions
int temps[]={29,33,34,35,35,32,29};
//outputs
System.out.println("Lowest high temperature of the week is "+min(temps));
System.out.println("Highest high temperature of the week is "+max(temps));
temps=increase(temps);
System.out.print("Temperatures after increasing: ");
for(int i=0;i<temps.length;i++)
System.out.print(temps[i]+" ");
}
}

Output:


Related Solutions

Write a program that uses an array of high temperatures for your hometown from last week...
Write a program that uses an array of high temperatures for your hometown from last week (Sunday – Saturday). Write methods to calculate and return the lowest high temperature (minimum) and a method to calculate and return the highest high temperature (maximum) in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array as a parameter and then creates...
Daily high temperatures in degrees Fahrenheit in the city of Lubbock for the last week havebeen...
Daily high temperatures in degrees Fahrenheit in the city of Lubbock for the last week havebeen as follows: 93, 94, 93, 95, 96, 88, 90. Using Excel’s Data Analysis add-in, a. Forecast the high temperature today, using a 3-day moving average. b. Forecast the high temperature today, using a 2-day moving average. c. Forecast the high temperature today, using weighted moving average with weights 0.5, 0.3 and 0.2 for the most recent, second most recent, and third most recent periods,...
Write a program that uses an array for time and temperature. The program should contain an...
Write a program that uses an array for time and temperature. The program should contain an array with 24 elements, each of which is holding a temperature for a single hour. Your program should have a function that lists all of the temperatures that are held in the array. Temperatures should be listed to console with one entry per line. Your program should have a function that lists a single temperature entry. You should ask the user for a number...
Daily high temperatures in St. Louis for the last week were as follows: 93, 94, 93,...
Daily high temperatures in St. Louis for the last week were as follows: 93, 94, 93, 95, 96, 88, and 90 (yesterday). a) Forecast the high temperature today, using a 3-day moving average. b) Forecast the high temperature today, using a 2-day moving average. c) Calculate the mean absolute deviation based on a 2-day moving average, covering all days in which you can have a forecast and an actual temperature.
Daily high temperatures in St. Louis for the last week were as​ follows: 92​, 94​, 93​,...
Daily high temperatures in St. Louis for the last week were as​ follows: 92​, 94​, 93​, 95​, 95​, 86​, 95 ​(yesterday). ​a) The high temperature for today using a​ 3-day moving average ​= 92 degrees ​(round your response to one decimal​ place). ​b) The high temperature for today using a​ 2-day moving average ​= 90.5 degrees ​(round your response to one decimal​ place). ​c) The mean absolute deviation based on a​ 2-day moving average​ = 3.3 degrees ​(round your response...
Daily high temperatures in St. Louis for the last week were as​ follows: 92 94, 93...
Daily high temperatures in St. Louis for the last week were as​ follows: 92 94, 93 95 97 90 93 ​(yesterday). ​a) The high temperature for today using a​ 3-day moving average ​= degrees ​(round your response to one decimal​ place). ​b) The high temperature for today using a​ 2-day moving average ​= degrees ​(round your response to one decimal​ place). ​c) The mean absolute deviation based on a​ 2-day moving average​ = nothing degrees ​(round your response to one...
Daily high temperatures in St. Louis for the last week were as​ follows: 9595​, 9191​, 9393​,...
Daily high temperatures in St. Louis for the last week were as​ follows: 9595​, 9191​, 9393​, 9494​, 9595​, 8686​, 9090 ​(yesterday). ​a) The high temperature for today using a​ 3-day moving average ​= degrees ​(round your response to one decimal​ place). ​b) The high temperature for today using a​ 2-day moving average ​= degrees ​(round your response to one decimal​ place). ​c) The mean absolute deviation based on a​ 2-day moving average​ = degrees ​(round your response to one decimal​...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In c++ Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value). The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In c++ Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value). The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In C++ c. The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function indexLowTemp: This function returns the index of the lowest low temperature in the array. These functions must all have the appropriate parameters.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT