0% found this document useful (0 votes)
4 views

Open Ended

The document describes a Java program that takes in temperature values throughout a week, calculates statistics like average, maximum, and minimum temperatures, and counts temperatures above and below the average. It uses arrays and loops to collect input from the user, calculate values, and output results.

Uploaded by

m.shayan.8401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Open Ended

The document describes a Java program that takes in temperature values throughout a week, calculates statistics like average, maximum, and minimum temperatures, and counts temperatures above and below the average. It uses arrays and loops to collect input from the user, calculate values, and output results.

Uploaded by

m.shayan.8401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Programming Fundamentals (SWE-102) SSUET/QR/144

Lab#10: Open-ended Lab


OBJECTIVE: - Open-ended Lab

Scenario: - "Temperature Calculator in Java."

Solution Output
import java.util.Scanner;

public class TemperatureCalculator {

public static void main(String[] args) {

System.out.println("\t\tTemperature Calculator in Celsius");

int numberOfEntries = 7;

Scanner scanner = new Scanner(System.in);

double[] temperatures = new double[numberOfEntries];

double sum = 0;

for (int i = 0; i < numberOfEntries; i++) {

System.out.print("Enter degree of temperature " + (i + 1) + ": ");

double temperature = scanner.nextDouble();

temperatures[i] = temperature;

sum += temperature;

double average = sum / numberOfEntries;

int aboveAverageCount = 0;

int belowAverageCount = 0;

for (double temperature : temperatures) {

if (temperature >= average) {

aboveAverageCount++;

} else {

belowAverageCount++;

System.out.println("List of temperatures throughout the week: ");

for (double temperature : temperatures) {

2023F-BSE-088
Programming Fundamentals (SWE-102) SSUET/QR/144

System.out.print(temperature + " ");

System.out.println();

System.out.println("Sum of all temperatures throughout the week: " + sum);

System.out.println("Average of all temperatures: " + average);

System.out.println("Max degree of temperature: " + findMax(temperatures));

System.out.println("Min degree of temperature: " + findMin(temperatures));

System.out.println("No of degrees greater than average: " + aboveAverageCount);

System.out.println("No of degrees less than average: " + belowAverageCount);

private static double findMax(double[] array) {

double max = array[0];

for (double value : array) {

if (value > max) {

max = value;

return max;

private static double findMin(double[] array) {

double min = array[0];

for (double value : array) {

if (value < min) {

min = value;

return min;

2023F-BSE-088

You might also like