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

  Loops and files

Convert an algorithm using control structures into Java and write a while loop

  Create your own date class

You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program:

  Implementation of encryption and steganography in java

This is a project report showing the essential details and coding structures related with the implementation of encryption techniques and steganography in JAVA.

  List various bindings that are needed to determine semantics

List the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language.

  Write a java program to register students for a college

Project is for designing and developing a College Registration program. Write a Java program to register students for a college

  Define private instance variable to hold boolean value

Write a Java Enumeration "LetterGrade" that represents letter grades A through F including plus and minus grades. Define a private instance variable to hold a boolean value.

  Java application prompt user to put in integer from keyboard

Write a java application that performs the following task: prompt user to put in an integer from the keyboard, search for the user input from the array created in step 1.

  Write java program to compute how much federal need to pay

Write a java application to calculate how much federal and state tax you need to pay. The program should accomplish the following task.

  Create java applet to represent grade of gas

Write a java applet (not a java application program) for costco gas station. The applet will first ask you whether you are a costco customer, then the grade of gas you want to use.

  Write a class that implements an ordered list of strings

In this problem you will write a class that implements an ordered list of Strings.

  Web engineering principles

web application development, Web Engineering methodology, UML-based Web Engineering (UWE), models to the expansion of web applications, Object Oriented Web Solutions (OOWS),Web Modeling Language (WebML) methodology, Object-Oriented Hypermedia Design..

  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.

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