Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8-1 Demo: The following code is a procedural way of writing code. It prints the

ID: 3814164 • Letter: 8

Question

8-1

Demo: The following code is a procedural way of writing code. It prints the weekly temperature, finds the min and max, and the average as well. h; int weekly TempC 1 69, 70, 71, 68, 66, 71, 70 int i, max 0, min 0; print temperatures for C 0; i weekly Temp length i++) 1 System. out.printfC"VnThe temperature on day %d was %d 'i, i 1 weekly Templi]); System. out.printfC''An n''); find the max, min temperature for C i 7 i++) 1 if Ci 0) max min weekly Templi] if CweeklyTempli] max) max. Weekly Templi] if Weekly Temp LLJ min) min weekly Templi] System. out.printfC"The Minimum temperature is: %d n", min System. out.printfC"The Maximum temperature is: %d n", max); get average float total 0, average for C 0; i 7 i++) total weekly TempCil average total weekly Temp. Length System. out.printlnC"The average temperage for the week is: average)

Explanation / Answer

import java.util.Scanner;

class Temeperatures{
    static int weekTemp[] = new int[7];

static void getTemperatures()
{
   
    Scanner sc=new Scanner(System.in) ;
    System.out.println("Enter 7 temperatures for the week");
for(int i=0;i<7;i++)
{
    weekTemp[i]=sc.nextInt();
   
     }
}


static void printTemperatures()
{
    System.out.println("Week Temeperatures is : ");
    for(int i=0;i<7;i++)
    System.out.println(weekTemp[i]);
}


static int getMax()
{
   int max = weekTemp[0];
for(int i=1;i<7;i++)
{
   if(weekTemp[i] > max)
    max = weekTemp[i];
}
return max;
}

static int getMin()
{
   int min = weekTemp[0];
for(int i=1;i<7;i++)
{
   if(weekTemp[i] < min)
    min = weekTemp[i];
}
return min;
}


static double getAverage()
{
   int sum = 0 ;
for(int i=0;i<7;i++)
{
  sum = sum + weekTemp[i];
}

return(sum/7);
}


static void printStatistics()
{
   System.out.println("Minimun Temperature is : " + getMin());
   System.out.println("Maximun Temperature is : " + getMax());
   System.out.println("Average Temperature is : " + getAverage());
}
   
  
  
  
public static void main(String args[]){
   

   
getTemperatures();
printTemperatures();
printStatistics();

}
}
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote