$25
The goal of this activity is to create a program that displays someone’s name, age, and gender, along with calculations for age in minutes and centuries well as max heart rate based on age and gender.
Directions: After you enter each segment of code below, be sure to compile and/or run your program. You should correct any errors prior to entering additional code.
Part 1: Getting user’s name and age
• Create the following class in jGRASP and save it as AgeStatistics.java as soon as you have entered the skeleton code for the class.
• Add Javadoc comments for the class and main method.
• Declare the following variables in the main method then compile your program:
• Add lines to prompt for and input the user’s gender after the previous code. Make sure that your program has the EXACT output as below.
----jGRASP exec: java -ea AgeStatistics
Enter your name: Pat
Enter your age in years: 71
Enter your gender (1 for female and 0 for male): 1
----jGRASP: operation complete.
Part 2: Converting age
• First, calculate and print the age of the user in minutes (minutes = years * 525600). Note that the tab escape sequence is included in the print statement; tab character is set to three spaces in jGRASP.
• Now calculate the age in centuries. You should be familiar with type conversion between numeric types.
----jGRASP exec: java -ea AgeStatistics
Enter your name: Pat
Enter your age in years: 71
Enter your gender (1 for female and 0 for male): 1
Your age in minutes is 37317600 minutes.
Your age in centuries is 0.71 centuries.
----jGRASP: operation complete.
Part 3: Max heart rate prompt
• Add the code to print max heart rate (note the print rather than println):
• Add an if-else statement that will be used to assign maxHeartRate to the max heart rate calculation for male and female. The comments below are there to help you in the Part 4
where you will insert the code to do the calculations on the line after each comment.
• Add one more print statement to print the max heart rate:
Part 4: Max heart rate calculations
• On your own, complete the if-else statement by adding an assignment statement for female and another for male to assign the appropriate expression below to the variable maxHeartRate.
The maximum heart rate is calculated as follows:
o Max heart rate for females:
209 - (0.7 * ageInYears)
o Max heart rate for males:
214 - (0.8 * ageInYears)
Test your program and make sure that the output is exactly as shown below. Your lab instructor may ask you to use a different set of values to test your program when you demo it for your activity grade.
Output # 1:
----jGRASP exec: java -ea AgeStatistics
Enter your name: Lucy
Enter your age in years: 25
Enter your gender (1 for female and 0 for male): 1
Your age in minutes is 13140000 minutes.
Your age in centuries is 0.25 centuries.
Your max heart rate is 191.5 beats per minute.
----jGRASP: operation complete.
Output # 2:
----jGRASP exec: java -ea AgeStatistics
Enter your name: Kao
Enter your age in years: 19
Enter your gender (1 for female and 0 for male): 0
Your age in minutes is 9986400 minutes.
Your age in centuries is 0.19 centuries.
Your max heart rate is 198.8 beats per minute.
----jGRASP: operation complete.