This is a Java program. The program must determine in what months there was the
ID: 657951 • Letter: T
Question
This is a Java program. The program must determine in what months there was the highest and lowest high, and in what months was the highest and lowest low, and in what months was the highest and lowest range. the calculation of the average, highest, and lowest must each be a separate method. Average, highest, and lowest methods must each take one array as the input. The picture I posted above is how the output should look like and the second picture shows the values you can input. There should be two loops, one for input and one for the calculation and output. The months should also be in an array.
Explanation / Answer
public class calculate
{
public static void highest_high(int[] h,String[] m)
{
int highest=h[0];
int flag=0;
for(int i=1;i<h.length;i++)
{
if(highest<h[i])
{
flag=i;
highest=h[i];
}
}
System.out.println( "highest high temperature is " + highest + "in " + m[flag] + " month ");
}
public static void highest_low(int[] h,String[] m)
{
int lowest=h[0];
int flag=0;
for(int i=1;i<h.length;i++)
{
if(lowest>h[i])
{
flag=i;
lowest=h[i];
}
}
System.out.println( "highest low temperature is " + lowest + "in " + m[flag] + " month ");
}
public static void lowest_high(int[] l,String[] m)
{
int highest=l[0];
int flag=0;
for(int i=1;i<l.length;i++)
{
if(highest<l[i])
{
flag=i;
highest=l[i];
}
}
System.out.println( "lowest high temperature is " + highest + "in " + m[flag] + " month ");
}
public static void lowest_low(int[] l,String[] m)
{
int lowest=l[0];
int flag=0;
for(int i=1;i<l.length;i++)
{
if(lowest>l[i])
{
flag=i;
lowest=l[i];
}
}
System.out.println( "lowest low temperature is " + lowest + "in " + m[flag] + " month ");
}
public static void average(int[] high,int[] low)
{
int high_avg,low_avg;
int sum_high=0,sum_low=0;
for(int i=0;i<high.length;i++)
{
sum_high+=high[i];
}
high_avg=(float)sum_high/12.0;
for(int i=0;i<low.length;i++)
{
sum_low+=low[i];
}
low_avg=(float)sum_low/12.0;
System.out.println( "Average high temperature is" + high_avg);
System.out.println( "Average low temperature is " + low_avg);
}
public static void main(String args[])
{
int[] high={41,40,51,60,75,82,89,88,78,70,59,50};
int[] low={10,18,35,41,60,68,70,72,65,55,40,30};
String[] months={"January","february","March","April","May","June",
"July","August","September","October","November","December"};
highest_high(high,months);
highest_low(high,months);
lowest_high(low,months);
lowest_low(low,months);
average(high,low);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.