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.

PLEASE DO NOT POST CODE ANSWER HERE. SEND SOLUTION TO [email protected]. DO NOT POST ANSWER HERE

THANK YOUU

Solutions

Expert Solution

import java.util.Scanner;
public class HighestAndLowest
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
//input array of temperatures
int temperatures[] = {34,24,45,41,37,32,33};
//maxTemperature method
int max = maxTemperature(temperatures);
//minTemperature method
int min = minTemperature(temperatures);
//displaying the temperature array
System.out.print("Temperature Values\t:");
for(int i:temperatures) {
   System.out.print(i+" ");
}
//
System.out.println("\nMax Of Temperatures\t:"+max);
System.out.println("Min Of Temperatures\t:"+min);
//increase the tempratures values by 10
temperatures = increaseTempratureByTen(temperatures);
System.out.print("Temperature Values (after increasing 10) :");
for(int i:temperatures) {
   System.out.print(i+" ");
}
}
// 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)
   private static int[] increaseTempratureByTen(int[] temperatures) {
       int result[] = new int[temperatures.length];
       int index = 0;
       for(int i:temperatures) {
           result[index++] = i+10;
       }
       return result;
   }
//   a method to calculate and return the highest high temperature (maximum) in the array
   private static int maxTemperature(int[] temperatures) {
       int max = temperatures[0];
for(int i = 0; i < temperatures.length; i++)
{
if(max < temperatures[i])
{
max = temperatures[i];
}
}
       return max;
   }
//   methods to calculate and return the lowest high temperature (minimum)
   private static int minTemperature(int[] temperatures) {
       int min = temperatures[0];
for(int i = 0; i < temperatures.length; i++)
{
if(min > temperatures[i])
{
min = temperatures[i];
}
}
       return min;
   }
}


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