DOC PREVIEW
UVA CS 101 - A MeDisplay compilation and run

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

102 Java basics There are two kinds of exercise—aerobic and anaerobicexercise. Normally, sustained activities such as bicy-cling, running or swimming are aerobic exercises.While activities requiring bursts of actions such asweight lifting and tennis are anaerobic exercises. Bothtypes of exercise have their advantages. For example,anaerobic exercise can stimulate muscle growth and aerobic exercise can raise yourmetabolism by stimulating the production of fat-burning enzymes. Figure 2.7 A MeDisplay compilation and run.2.12 PROGRAMMING PROJECT — TRAINING ZONEThe objective of this case study is to practice interactive programming in the context of problem solvingProgramming project — training zone 103For a sustained activity to be an aerobic exercise there needs to be an elevation in theheart rate. However, the elevation cannot be extreme. If the elevation is extreme, thenmuscles are oxygen deprived and they burn sugars rather than fat. Research indicates thatthere is a heart beat rate training zone that should be kept in order to get the maximumaerobic effect from an exercise. The actual training zone for a person is based on manyfactors, such as the individual’s normal heart rate, fitness, health, weight, etc. However,there are formulas indicating reasonable training zones for the majority of fit people withnormal heart rates. The formula used in this section comes from HealthCentral.com.The formula work as follows: subtract the age of interest from 220; 65% of that value isthe low end of the training zone range and 80% of that value is the high end of the train-ing zone range.The goal of this case study is to develop a program that computes a training zoneaccording to the following problem statement.Provide an interactive training zone calculator that prompts a user forher or his age. The calculator program then computes and displays thetraining zone for that age. The low end of the training zone is 65% of thedifference between 220 and the specified age. The high end of the train-ing zone is 80% of the difference between 220 and the specified age.ANALYSIS AND DESIGNBefore determining the necessary information structures and algorithm, you shoulddepict a sample input/output behavior. A depiction should help clarify what informationis being provided and what information is to be computed. Furthermore, if the software isbeing developed for a client, then it also aids you in verifying with the client that theproper problem is being solved. An example of a possible input/output behavior for thetraining zone calculator is given in Figure 2.8. Figure 2.8 A possible training zone calculator console window display.104 Java basicsAn analysis of the problem statement indicates one piece of information that must begotten from the user—the age of interest. From that information and the training zoneformula you derive the lower and upper heart beat rates for the training zone associatedwith that age of interest. An analysis of the problem also indicates that in developing analgorithm three integer variables are appropriate: ageOfInterest, lowBeatRate, and high-BeatRate. In addition, three constants are appropriate: BASE_RATE with value 220,LOW_ZONE_MULTIPLIER with value 65%, and HIGH_ZONE_MULTIPLIER withvalue 80%. From the preceding discussion, an algorithm for solving the problem is relativelyeasy.Step 1. Provide a suitable legend for the calculator.Step 2. Prompt the user for the age for which they desire a suggested trainingzone.Step 3. Extract the user-specified age and assign it to variable ageOfInterest.Step 4. Compute the low heart beat rate by assigning lowBeatRate the value ofthe expression LOW_ZONE_MULTIPLIER × (BASE_RATE – ageOfIn-terest).Step 5. Compute the high heart beat rate by assigning highBeatRate the value ofthe expression HIGH_ZONE_MULTIPLIER × (BASE_RATE – ageOfIn-terest).Step 6. Display the training zone information as defined by ageOfInterest, low-BeatRate, and highBeatRate. ImplementationProducing a Java program TrainingZone.java from the suggested algorithm can bedone nicely with a single class TrainingZone. The class should be documented and laidout appropriately. For example, the code should make use of program header and methodcomments, whitespace, and a consistent indentation scheme. TESTINGOne way to test a program informally is to do a hand-check—compute by hand what theoutput should be for several different ages. Then run the program using those same agesand compare the results. Determine for any discrepancies whether the program or handcalculation is incorrect. If the program is incorrect, review the formulas already given andyour implementation of them. Also consider adding temporarily statements displayingintermediary results in an effort to determine where your program’s correctness breaksdown. (Such statements are called debugging statements.) Testing and debugging isexamined in detail in Chapter


View Full Document

UVA CS 101 - A MeDisplay compilation and run

Documents in this Course
Classes

Classes

53 pages

Recursion

Recursion

15 pages

Iteration

Iteration

88 pages

PLEDGED

PLEDGED

6 pages

Objects

Objects

33 pages

PLEDGED

PLEDGED

11 pages

CS 101

CS 101

42 pages

Classes

Classes

83 pages

Iteration

Iteration

92 pages

Classes

Classes

186 pages

Classes

Classes

208 pages

Hardware

Hardware

21 pages

Arrays

Arrays

70 pages

Load more
Download A MeDisplay compilation and run
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view A MeDisplay compilation and run and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view A MeDisplay compilation and run 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?