Program to find maximum-minimum of sequence of values

Assignment Help JAVA Programming
Reference no: EM1371784

A common task that must be done in a loop is to find the maximum and minimum of a sequence of values. The file Temps.java contains a program that reads in a sequence of hourly temperature readings over a 24- hour period. You will be adding code to this program to find the maximum and minimum temperatures. Do the following:

1. Save the file to your directory, open it and see what's there. Note that a for loop is used since we need a count-controlled loop. Your first task is to add code to find the maximum temperature read in. 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 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. 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. NOTE: If the current temperature is NOT larger, DO NOTHING!

2. Add code to print out the maximum after the loop. Test your program to make sure it is correct. Be sure to test it on at least three scenarios: the first number read in is the maximum, the last number read in is the maximum, and the maximum occurs somewhere in the middle of the list. For testing purposes you may want to change the HOURS_PER_DAY variable to something smaller than 24 so you don't have to type in so many numbers!

3. Often we want to keep track of more than just the maximum. For example, if we are finding the maximum of a sequence of test grades we might want to know the name of the student with the maximum grade. Suppose for the temperatures we want to keep track of the time (hour) the maximum temperature occurred. To do this we need to save the current value of the hour variable when we 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 your 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.)

4. Add code to print out the time the maximum temperature occurred along with the maximum.

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

Reference no: EM1371784

Questions Cloud

One resource production possibility frontier : Assume that a simple society has economy with only one resource, labor. Labor can be employed to produce only two commodities- X, a necessity good (food) and Y, a luxury good ( music and entertainment). Assume the economy produced at a point inside..
Describe mechanism used for signaling between client-server : Describe the mechanism used for signaling between client and server to indicate that persistent connection is being closed. Can client, server, or both signal close of connection?
Make a report that explain the details of the organization : Make a report that explain the details of the organization or corporation and why it is your dream job and overview of the organization or corporation
Computing quantity-price : Night Timers Co. manufactures glow-in-the dark products in 10 ft. rolls. At present the company's maximum production capacity is 140,000 rolls per year. The cost is stated as: C= $50,000 + 0.25 Q.
Program to find maximum-minimum of sequence of values : Common task which should be done in loop is to find maximum and minimum of sequence of values. File Temps.java contains program which reads in sequence of hourly temperature readings over 24- hour period.
Determining learning rate : A production lot of 25 units required 103.6 hours of effort. Accounting records show that first unit took seven hours. What was the learning rate?
Question about reserve prices and extended warranties : A reserve value is a minimum value set by the auctioneer. If no bidder is willing to pay the reserve price, the item is unsold at a profit of $0 for the auctioneer.
Question on patent system : Government involvement in general scientific research has been justified on the grounds that advances in knowledge are public goods- once produced, information can be shared at virtually no cost.
Determining linear programming-maximizing profits : A manufacturer of outdoor clothing makes wax jackets and trousers. Each jacket requires 1 hour to manufacture, whereas each pair of trousers takes 40 minutes.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write java program which will permit user to input data

Write the Java Program which will permit the user to input data. The data will be validated using a loop that requires the user to input the data until it is correct or in the correct range. T

  Java problem - g queue

A queue is an ordered collection of items in which the removal of items is restricted to the FIFO ( rst in rst out) principle.

  Develop java applet that will help elementary school student

Develop a Java applet that will help an elementary school student learn multiplication. Use the Math.random method or a Random object to produce two positive one-digit integers.

  Create java program to describe inheritance and polymorphism

Create a Java program based on the geometric shapes example described at the beginning of this lesson using Classes Square, Triangle, Rectangle, and Circ leto help describe inheritance and polymorphism.

  Evaluate the rtas resource requirements

Design and implement a set of classes and interfaces and use them to evaluate the RTA's resource requirements.

  Can linear search algorithm be encoded using recursion

Determine the average amount of time people spend waiting for tables and provide examples from the "real world" of unsorted lists, sorted lists, indexed lists, lists that permit duplicate elements, and lists that do not permit duplicate elements

  Distributed systems

Build robust, secure distributed systems using advanced programming techniques

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Sorted list adt and the binary search tree adt

Explain the differences between our specifications of the Sorted List ADT and the Binary Search Tree ADT.

  Robot preparing for competition

Create an event so that the skateboard can be controlled by game player

  Write java program to store values retrieved from user-array

Write a Java program named Arrays6_2GF.java Use an array to store values retrieved from user input. The number of integers to be entered (the length of the array )should also be retrieved through user input.

  Create a class safestack that implements a stack of strings

Create a class SafeStack that implements a stack of strings

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