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

  Implementation activities of software development

Analysis, design, and implementation activities of software development

  What position along the chord does minimum pressure occur

At what position along the chord does the minimum pressure occur? What is special about the point where C p is a maximum?

  Create bean jsp program which will compute simple interest

Create the bean which will compute Simple Interest. Use bean in JSP program. Accept details of saving like principal amount, rate of interest, period-in years from user and show amount

  World data app

Prepare WorldDataApp project. It implements the NameIndex portion, including creating it in SetupProgram, and searching, viewing and updating it in UserApp program.

  Using a linked implementation of graph write a method

Write a method that takes two nodes as input and returns true if joining an edge between these two nodes, forms a duplicate path to one of the input nodes within the graph.

  Create application uses two-dimensional arrays

Create an application which uses 2-dimensional arrays to keep track of 5 students' grades, with each student having 3 different classes.

  Cascading style sheet to a website

Compare and contrast the process of adding JavaScript and a Cascading Style Sheet to a Website. Determine if they can be used simultaneously in a page.

  Creating the gui for the game interface

A GUI-based application that allows a user to play a simple trivia game

  Java class to accept a user-s hourly rate of pay

Write a class that accepts a user's hourly rate of pay and the number of hours worked. Display the user's gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay - withholding).

  Methods

Assignment describe the basic working of methods. How to write a method in java and how to call a method.

  Solving programming problems

Write a computer program that will figure out the total of an order when given the amount of the order ($1000) and a sales tax rate of eight percent.

  Write java application to input three integers from user

Write Java application that inputs three integers from user and displays sum, average, product, smallest, and largest of the numbers.

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