/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
// Main method
public static void main
(String[] args
) {
// Create a new scanner
Scanner input
= new Scanner
(System.
in);
// Set array list
int[] tempList = new int[7];
// Prompt user for input and store input
System.
out.
println("Enter the hightest temperature of each day for a week (starting on Sunday): "); for(int i = 0; i < tempList.length; i++)
tempList[i] = input.nextInt();
// Averages temperature
double avgTemp = avgTemp(tempList);
System.
out.
printf("The average temperature of the week is: %.2f degree %n", avgTemp
);
// Display hottest temperature
int maxTemp = maxTemp(tempList);
System.
out.
println("The highest temperature of the week is: " + maxTemp
+ " degree");
// Display coldest temperature
int minTemp = minTemp(tempList);
System.
out.
println("The coldest temperature of the week is: " + minTemp
+ " degree");
int[] maxTempList = searchTemp(tempList, maxTemp);
for(int i = 0; i < maxTempList.length; i++){
System.
out.
print("The hottest days of the week are: " +maxTempList
[i
]);
System.
out.
print(weekDay
(tempList,maxTemp
)); }
}
// Average the temperature
public static double avgTemp(int[] array)
{
int tempTotal = array[0];
// Total temperature values
for(int i = 0; i < array.length; i++)
tempTotal = array[i]+tempTotal;
// Return temperature average.
return ((double)tempTotal/array.length);
}
// Get hottest temperature
public static int maxTemp(int[] array)
{
int max = array[0];
// Check and replace max temp
for(int i = 1; i < array.length; i++){
if(max < array[i])
max = array[i];
}
return max;
}
// Get coldest temperature
public static int minTemp(int[] array)
{
int min = array[0];
for(int i = 1; i < array.length; i++){
if(min > array[i])
min = array[i];
}
return min;
}
// Return days
public static String weekDay
(int i,
int[] array
) {
int[] displayWeekDay = searchTemp(array, i);
for(i = 0; i < displayWeekDay.length; i++){
switch(i)
{
case 0: return "Sunday";
case 1: return "Monday";
case 2: return "Tuesday";
case 3: return "Wednesdays";
case 4: return "Thursday";
case 5: return "Friday";
case 6: return "Saturday";
}
}
return weekDay;
}
// Finds the index of the hottest/coldest days
public static int[] searchTemp(int[] temp, int key)
{
int count = 0;
for(int i = 0; i < temp.length; i++){
if(temp[i] == key)
count++;
}
int[] index = new int[count];
for(int j = 0; j < index.length; j++){
for(int i = 0; i < temp.length; i++){
if(temp[i] == key){
if(j > 0 && index[j - 1] == i)
continue;
else{
index[j] = i;
break;
}
}
}
}
return index;
}
}