University of Pittsburgh
  Spring 2004
CS0007:  Introduction to Computer Programming
Assignment 2: Training Heart Rate
DUE DATE
Wednesday, Jan 28, midnight
VALUE
25 points
BACKGROUND
Chapter 2, JBD

Have your old handouts ready as a reference and assignment 1.  

Objectives

This assignment is similar in nature to several of the examples we did in class.  You will be following the "calculator" style of program that goes:  (1) get input, (2) calculate answer, (3) print results.  You will be declaring a few variables and using some built-in methods.

What to do

You will write a small program to calculate the user's training heart rate (THR).  That's how fast your heart should be beating to get the most out of every workout.  Your program will specifically be calculating the aerobic zone (there are several different zones - see below for a link to more information).

To calculate someone's aerobic THR, you need to use the following formula:

THR = ((MaxHeartRate - RestingHeartRate) X .75) + RestingHeartRate

To find someones Maximum Heart Rate, just subtract their age from 214.  Resting Heart Rate varies from person to person, but is generally between 60 and 80.

Your program will therefore need to ask the user for his/her age and resting heart rate.  Both of these variables should be of type int.  You will also need a variable to hold the result, which should be of type double.


Sample output

Here is a sample of how your program might look when executed.  You don't have to do exactly this, but it should be similar.

(22) unixs1 $ java youridTHR
Welcome to the Training Heart Rate calculator.
  Please enter your age in years ==> 24
  Please enter your resting heart rate (beats per min) ==> 65
Your THR is: 158.75
(23) unixs1 $


Don't worry if your output turns out kind of ugly - formatting doubles when they are printed is a bit hairy, so we'll learn that later.

Requirements & Handing your work in

Before you hand your program in, make sure you meet these requirements:
  • Your filename and class name must begin with you user id.
  • You must use comments in your program in the following places:
    • At the top:  include your name, the date, and a brief (2-3 line) description of the program
    • In comments, state each big section:  Input, Calculation, Output
To hand your work in:
  • copy both your java source file and your compiled .class file to the handin directory.
  • Use assignment2 as the directory name (not "sample" or "assignment1"). 
See assignment 1 or the handing your code in handout to remind you of the steps.  Don't forget to verify the handin using ls.

Suggestions/Hints

This is fairly similar to the programs we wrote together in class.  My advice is to model your program after them.  Note:  Do exactly what is asked, please don't make your program do more or less than this.  This complicates the grading process which is difficult as it is.   If you would like to go above and beyond, that is fine, just don't turn it in.  You are always welcomed to visit us during office hours to talk about advanced topics.

The THR formula shown here is simplified.  If you want to see a full version of THR, have a look at this site.

Last Updated:1/21/04 by H. Chad Lane