QUESTION IMAGE
Question
write a program that will collect as input from the user, four temperature values (as double values), and then compute and display the following statistical information regarding those temperature values: - minimum temperature - maximum temperature - average temperature - skew of the temperature values - range of the temperature values the range of the temperature values will be the difference between the maximum temperature and the minimum temperature. the skew of the temperature values will be the deviation of the average from the midpoint between the minimum and maximum temperature values as a percentage of the range. for example, with an average temperature of 75.0 and a minimum temperature of 64.0 and a maximum temperature of 84.0, the skew will be 5.0%. this is because the difference between the average (75.0) and the midpoint between the minimum and maximum temperature values (74.0) is 1.0, which is 5.0% of the range (20.0). all output values will be double values, displayed with one decimal point of precision. here are some examples of what the user should see when the program runs example 1 enter first temperature : 64 enter second temperature : 72 enter third temperature : 84 enter fourth temperature : 80 min : 64.0 max : 84.0 average : 75.0 skew : 5.0% range : 20.0 example 2
Step1: Define variables & get inputs
Declare double variables for 4 temps, min, max, avg, skew, range. Read 4 user inputs.
import java.util.Scanner;
public class TemperatureStats {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double temp1, temp2, temp3, temp4;
System.out.print("Enter first Temperature : ");
temp1 = input.nextDouble();
System.out.print("Enter second Temperature : ");
temp2 = input.nextDouble();
System.out.print("Enter third Temperature : ");
temp3 = input.nextDouble();
System.out.print("Enter fourth Temperature : ");
temp4 = input.nextDouble();
Step2: Calculate min temperature
Use Math.min() to find the lowest value.
double min = Math.min(Math.min(temp1, temp2), Math.min(temp3, temp4));
Step3: Calculate max temperature
Use Math.max() to find the highest value.
double max = Math.max(Math.max(temp1, temp2), Math.max(temp3, temp4));
Step4: Calculate average temperature
Sum all temps, divide by 4.
double avg = (temp1 + temp2 + temp3 + temp4) / 4.0;
Step5: Calculate temperature range
Subtract min from max.
double range = max - min;
Step6: Calculate temperature skew
Compute midpoint, find deviation from avg, divide by range, multiply by 100.
double midpoint = (min + max) / 2.0;
double skew = ((avg - midpoint) / range) * 100;
Step7: Format & display outputs
Print all values with 1 decimal place.
System.out.printf("%-10s: %.1f%n", "Min", min);
System.out.printf("%-10s: %.1f%n", "Max", max);
System.out.printf("%-10s: %.1f%n", "Average", avg);
System.out.printf("%-10s: %.1f%%%n", "Skew", skew);
System.out.printf("%-10s: %.1f%n", "Range", range);
input.close();
}
}Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
The complete Java program above will:
- Prompt the user to enter four temperature values
- Compute the minimum, maximum, average, skew, and range of the values
- Display all results formatted to one decimal place, matching the provided example output.
When run with the input 64, 72, 84, 80, the output will be:
Min : 64.0
Max : 84.0
Average : 75.0
Skew : 5.0%
Range : 20.0