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...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. These methods MUST be your original code.   Your program should output all the values in the array and then output the average high and the...
Write a program that uses a two dimensional array to store the highest and lowest temperatures...
Write a program that uses a two dimensional array to store the highest and lowest temperatures for each month of the calendar year. The temperatures will be entered at the keyboard. This program must output the average high, average low, and highest and lowest temperatures of the year. The results will be printed on the console. The program must include the following methods: A method named inputTempForMonth whose purpose is to input a high and a low temperature for a...
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​...
Daily high temperatures in St. Louis for the last week were as​ follows: 9292​, 9494​, 9393​,...
Daily high temperatures in St. Louis for the last week were as​ follows: 9292​, 9494​, 9393​, 9595​, 9797​, 9090​, 9393 ​(yesterday). ​a) The high temperature for today using a​ 3-day moving average ​= 93.3393.33 degrees ​(round your response to one decimal​ place). ​b) The high temperature for today using a​ 2-day moving average ​= 91.591.5 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT