In: Computer Science
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
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;
}
}