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

Java programming After you turn in the Part I, you may use computer to complete

ID: 3854312 • Letter: J

Question


Java programming After you turn in the Part I, you may use computer to complete the following program. You also can use your book or notes if necessary. Print out java file. Write a program that ask user to enter hourly temperature for a day (24 hours). The program then will print out average temperature of the day and the hour which has the highest temperature. Your program must include two methods that are defined to work with the given main methods. One methods is named as readData which will read hourly temperature into an array. Another method is named as MaxArray which will take an array as argument and return the highest element of the array. You need to do: 1. Define method: readData 2. Define method: MaxArray 3. Add other code of the given main method to ensure the program perform correctly class Arraydata { public static void main(String [] arg) { double temp[], max: temp = new double[24]: readData(temp): max = Max(temp): System.out.println("highest value in the array is "+max): //add code to print out the daily average temperature //add code to print out the hour which has the highest temperature of the day } //define two methods to compete the program

Explanation / Answer

Arraydata.java

import java.util.Scanner;

public class Arraydata {

public static void main(String[] args) {

double temp[], max, average;

temp = new double[24];

readData(temp);

max = MaxArray(temp);

double total = 0;

for(int i=0; i<temp.length; i++){

total= total + temp[i];

}

average = total/temp.length;

System.out.println("highest value in the array is "+max+" Average daily temparature is : "+average);

}

public static void readData(double temp[]){

Scanner scan = new Scanner(System.in);

for(int i=0; i<temp.length; i++){

System.out.println("Please enter temparatur at "+(i+1)+" hour : ");

temp[i] = scan.nextDouble();

}

}

public static double MaxArray(double temp[]){

double max = 0;

for(int i=0; i<temp.length; i++){

if(max < temp[i])

max = temp[i];

}

return max;

}

}

Output:

Please enter temparatur at 1 hour :
11
Please enter temparatur at 2 hour :
22
Please enter temparatur at 3 hour :
33
Please enter temparatur at 4 hour :
44
Please enter temparatur at 5 hour :
12
Please enter temparatur at 6 hour :
13
Please enter temparatur at 7 hour :
14
Please enter temparatur at 8 hour :
15
Please enter temparatur at 9 hour :
16
Please enter temparatur at 10 hour :
17
Please enter temparatur at 11 hour :
18
Please enter temparatur at 12 hour :
19
Please enter temparatur at 13 hour :
20
Please enter temparatur at 14 hour :
21
Please enter temparatur at 15 hour :
23
Please enter temparatur at 16 hour :
24
Please enter temparatur at 17 hour :
25
Please enter temparatur at 18 hour :
26
Please enter temparatur at 19 hour :
27
Please enter temparatur at 20 hour :
66
Please enter temparatur at 21 hour :
55
Please enter temparatur at 22 hour :
77
Please enter temparatur at 23 hour :
99
Please enter temparatur at 24 hour :
88
highest value in the array is 99.0
Average daily temparature is : 32.708333333333336

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