import java.util.Scanner; public class heartMonitor { /** * Task: Make the necessary changes in this code to run the statement * * System.out.println("Invalid option. Inform age and heart rate first."); * * if the user selects options 3, 4, or 5 before entering * their age and heart rate correctly. */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int choice = 0; // User age, in years int age = 0; // Current user heart rate int heartRate = 0; // Three consecutive heart rate measurements int hr1, hr2, hr3; while (choice != 6) { System.out.println("\n Heart Monitor Menu:"); System.out.println("1. Enter age"); System.out.println("2. Enter heart rate"); System.out.println("3. Compute maximum heart rate"); System.out.println("4. Compute heart rate zone"); System.out.println("5. Compute heart rate variation"); System.out.println("6. Exit"); System.out.print("Enter your choice (1-6): "); choice = scanner.nextInt(); if (choice == 1) { System.out.print("Enter your age [2-150]: "); age = scanner.nextInt(); if (checkAge(age)) System.out.println("You are " + age + " years old."); else { System.out.println("Invalid value. Try again."); age = 0; } } else if (choice == 2) { System.out.print("Enter your heart rate [40-220]: "); heartRate = scanner.nextInt(); if (checkHeartRate(heartRate)) System.out.println("Your current heart rate is " + heartRate + "."); else { System.out.println("Invalid value. Try again."); heartRate = 0; } } else if (choice == 3) { System.out.println("Your maximum heart rate is " + maximumHeartRate(age) + "."); } else if (choice == 4) { System.out.println("Your heart rate zone is " + heartRateZone(age, heartRate)); } else if (choice == 5) { System.out.print("Enter three heart rate measurement separated by a space: "); hr1 = scanner.nextInt(); hr2 = scanner.nextInt(); hr3 = scanner.nextInt(); System.out.println("Your heart rate is " + heartRateVariation(hr1, hr2, hr3) + "."); } else if (choice == 6) System.out.println("Exiting the program. Goodbye!"); else System.out.println("Invalid choice. Please enter a number between 1 and 5."); } scanner.close(); } /** * A valid age is a number in the inverval [2,150] * If the user inputs an invalid number return false. * If the age is valid, return true. */ public static boolean checkAge(int ag) { // Implement checkAge return false; } /** * A valid heart rate is a number in the inverval [40,220]. * If the user inputs an invalid number return false. * If the heart rate is valid, return true. */ public static boolean checkHeartRate(int hr) { // Implement checkHeartRate return false; } // Task: compute user's maximum heart rate // and return an integer number // The maximum heart rate is compute as: // maximumHeartRate = 220 - age public static int maximumHeartRate(int age) { // Implement maximumHeartRate int mhr = 0; return mhr; // Replace with actual result } /** * Task: compute user's heart rate zone. * The heart rate zone is a number in the * interval [1-5] according to the following rules: * zone = 1, if current heart rate is less than 60% of the maximum heart rate * zone = 2, if current heart rate is greater than or equal to 60% and less than * 70% of the maximum heart rate * zone = 3, if current heart rate is greater than or equal to 70% and less than * 80% of the maximum heart rate * zone = 4, if current heart rate is greater than or equal to 80% and less than * 90% of the maximum heart rate * zone = 5, if current heart rate is greater than or equal to 90% of the * maximum */ public static int heartRateZone(int age, int hr) { // Implement heartRateZone int zone = 0; // ... return zone; // Return the actual zone } // Task: given three measurements of the user's heart rate, hr1, hr2, and, hr3, // update the boolean variables: increaseing, decreasing and stable. // The variable increasing should be set to true if the input values are // strictly increasing // The variable decreasing should be set to true if the input values are // strictly decreasing // The variable stable should be set to true if the input values are all equal. public static String heartRateVariation(int hr1, int hr2, int hr3) { // Implement heartRateVariation boolean increasing = false; boolean decreasing = false; boolean stable = false; // ... if (increasing) return "increasing"; else if (decreasing) return "decreasing"; else if (stable) return "stable"; else return "oscillating"; } }