Find the maximum temperature read

Assignment Help Basic Computer Science
Reference no: EM132099018

Need Major Help. I"m so close! looking to add to this code to find the maximum and minimum temperatures.

Looking to add code to find the maximum temperature read in. I know that in general to find the maximum of a sequence of values processed in a loop you need to do two things:

  • 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 valuesmallerthan 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 variablemaxTempto 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: EM132099018

Questions Cloud

Write a program that reads a customer account number : Write a program that reads a customer's account number (int type), account type (char type; s or S for savings, c or C for checking),
Familiarity with the eclipse environment : After you gain familiarity with the Eclipse environment, you are going to create a very simple Java program, and run it using Eclipse. Following is the sample c
Define a class named payment that contains : Define a class named Payment that contains a member variable of type double that stores the amount of the payment and appropriate
Retail price calculator : program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example:
Find the maximum temperature read : Need Major Help. I"m so close! looking to add to this code to find the maximum and minimum temperatures.
Must input how many questions they want : I need a program that will give the user an addition test. Before the test begins the user must input how many questions they want and what the largest number
Welcome banner and a farewell : My professor wants a welcome banner and a farewell banner in a method in main class of my program to launch as soon as the program starts and ends I'm just a li
Create a very simple four function integer calculator : Create a very simple four function integer calculator with buttons for Add, Subtract, Multiply, and Divide, and with two text-type input fields.
Create the program for an atm machine : How can we create the program for an ATM MACHINE to perform the following tasks

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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