Find the minimum temperature

Assignment Help JAVA Programming
Reference no: EM131914299

You need a variable that will keep track of the maximum of the values processed so far. This variable must be initialized before the loop. There are two standard techniques for initialization: one is to initialize the variable to some value smaller than any possible value being processed; another is to initialize the variable to the first value processed. In either case, after the first value is processed the maximum variable should contain the first value. For the temperature program declare a variable maxTemp to hold the maximum temperature we need to Initialize it to -1000 (a value less than any legitimate temperature).

The maximum variable must be updated each time through the loop. This is done by comparing the maximum to the current value being processed. If the current value is larger, then the current value is the new maximum. So, in the temperature program, add an if statement inside the loop to compare the current temperature read in to maxTemp. If the current temperature is larger set maxTemp to that temperature. and : If the current temperature is NOT larger, DO NOTHING!

also need to Add code to print out the maximum after the loop.

want to keep track of the time (hour) the maximum temperature occurred. save the current value of the hour variable when update the maxTemp variable. This of course requires a new variable to store the time (hour) that the maximum occurs. Declare timeOfMax (type int) to keep track of the time (hour) the maximum temperature occurred. Modify if statment so that in addition to updating maxTemp you also save the value of hour in the timeOfMax variable. (WARNING: you are now doing TWO things when the if condition is TRUE.)

need to print out the time the maximum temperature occurred along with the maximum.

also need to add code to find the minimum temperature and the time that temperature occurs. The idea is the same as for the maximum. need a separate if when updating the minimum temperature variable (that is, don't add an else clause to the if that is already there).

// Temps.java

//

// This program reads in a sequence of hourly temperature

// readings (beginning with midnight) and prints the maximum

// temperature (along with the hour, on a 24-hour clock, it

// occurred) and the minimum temperature (along with the hour

// it occurred).

// **********************************************************


import java.util.Scanner;


public class Temps

{

//----------------------------------------------------

// Reads in a sequence of temperatures and finds the

// maximum and minimum read in.

//----------------------------------------------------

public static void main (String[] args)

{

final int HOURS_PER_DAY = 24;


int temp; // a temperature reading


Scanner scan = new Scanner(System.in);


// print program heading

System.out.println ();

System.out.println ("Temperature Readings for 24 Hour Period");

System.out.println ();


for (int hour = 0; hour < HOURS_PER_DAY; hour++)

{

System.out.print ("Enter the temperature reading at " + hour +

" hours: ");

temp = scan.nextInt();

}


// Print the results

}

}

Reference no: EM131914299

Questions Cloud

Does the observed data contradict the company claim : Does the observed data contradict the company's claim? Formulate and test the appropriate hypotheses at the 2.5% level of significance.
How immigrants are absorbed into a new culture : Write an essay that details how immigrants are absorbed into a new culture. In your essay, address how the racial and/or ethnic composition of an immigrant.
What is the p-value for the appropriate test : He picks an SRS of 30 recruits and calculates their mean 5K time is 16 minutes 52 seconds, with a standard deviation of 25 seconds.
Discuss the characteristics of persuasive writing : Apply the characteristics of persuasive writing to turn the Literature Review into a persuasive argument. The persuasive argument begins with a strong hook.
Find the minimum temperature : find the minimum temperature and the time that temperature occurs. The idea is the same as for the maximum. need a separate if when updating the minimum
What amount of the travel costs can melissa deduct as busine : Suppose that while Melissa was on the coast, she also spent two days sightseeing. What amount of the travel costs can Melissa deduct as business expenses?
Different nonzero digits followed by three different letters : If each licence plate contains three different nonzero digits followed by three different letters
How does brison define pornography : What does Mill say is "assumed" by the person who wishes to suppress an opinion because they are sure it is false?
Distribution function for the random variable : Suppose that the random variable X has a geometric distribution with a mean of 2.5. Determine the following probabilities:

Reviews

Write a Review

JAVA Programming Questions & Answers

  Using a linked implementation of graph write a method that

using a linked implementation of graph write a method that takes two nodes as input and returns true if joining an edge

  Develop a java application

Your task is to develop a Java Application that allows the user to read travel booking data from a text file, save data in a file, display data in a text area, sort data by booking name and search data by booking name.

  How do you figure out how to declare a variable

How do you figure out how to declare a variable? How do you know what type of variable to use? What is the best way to name a variable and why? What are the differences between an integer variable and a floating point variable? When and why do dat..

  Creation of a virtual world java application

Implement classes that meet the given specifications of object instance variables and behaviors and create operative algorithms using sequential logic structures, decision control structures, and loops

  Write the exam statistics program

Programming Assignment #2 The Exam Statistics Program Include a Table of Contents here... * Assignment #2: The Exam Statistics Program

  Performance of both the threaded and non-threaded versions

Please modify the Java program by adding threads, and analyze the performance of both the threaded and non-threaded versions.

  What does the variable x contain

What does the variable x contain at the end of each of these computations? If the code is not legal in Java, say so.

  Implement an inheritance hierarchy based on the following

Implement an inheritance hierarchy based on the following specifications for Account class, Checking Account class, and Savings Account class Methods: processDeposit ( ) - accepts a single double parameter containing the deposit amount. Updates the ..

  Create a new child class to model an equilateral triangle

You are to create a new child class to model an equilateral triangle. An equilateral triangle is a triangle where the length of all three sides is the same.

  Create a method that when passed any sequence

Create a method that when passed any sequence in this way, checks all the numbers to find if any add up to the capacity of the box. If a solution is found

  Develop a mobile game using any game scenario of your choice

Using the J2ME platform, develop a mobile game using any game scenario of your choice. You are required to provide the following features in your implementation: 2D implementation using sprite, game canvas and tiled layer

  Analyze the running time of method

Analyze the running time of method - Choose a partitioning strategy you like to pick a pivot element from the sequence. Analyze how different portioning strategies may impact on the performance of the sorting algorithm.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd