Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The rating of metabolic equivalents (MET) is used to describe the intensity unit

ID: 3884829 • Letter: T

Question

The rating of metabolic equivalents (MET) is used to describe the intensity units to each activity. Based on the MET value of the activity and the length of time you spent performing it, you can calculate the number of calories you burned by an activity. Your weight (in kg) and the duration of the activity (in minutes) are used to calculate the Calories burned by exercise. If you weigh more then you burn more Calories for that activity. Here is the formula: Calories burned by exercise = ((METs * 3.5 * weight in kg)/200) * duration in minutes. Here is a sample run: How much do you weigh, in pounds: 150 How long did you do the activity (in minutes): 10 What is the MET value for your activity? 5 The number of Calories you have burned is: 69.675 You will need to convert the pounds entered to kilograms to do the calculation. The MET values are taken from specific tables. You will find these tables in Moodle. Add a password to the beginning of the program. The user must enter CAL2017 to start the program, otherwise give the message "The password you have entered is not correct"'. Only give the user one chance to get in the program. Are you using sequence, if, or loop for this? Modify the program so it starts out (after the correct password) asking if the user wants to compute the number of Calories burned. If they do, then go through the calculations. Compute the total Calories burned, the average Calories burned and count how many times the calculations have been done. Should the average calculation be done every time the user enters data? Also, when one Calorie calculation is complete, ask the user "Do you want to compute another Calorie Calculation?"

Explanation / Answer

CaloriesBurnt.java

import java.util.Scanner;

public class CaloriesBurnt {

public static void main(String[] args) {
// Declaring variables
char choice;
double wtInPounds, caloriesBurned, wtInKg, totCalories = 0.0, avgColories = 0.0;
int timesInMins, metVal, count = 0;
final String PASWORD = "CAL2017";
String pass;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Password: ");
pass = sc.next();

if (pass.equals(PASWORD)) {

System.out.print("Do you want to compute the number of Calories burned ?(Y/N) ");
choice = sc.next(".").charAt(0);

if (choice == 'N' || choice == 'n') {
// Getting the input entered by the user
System.out.print("How much do you weight in pounds :");
wtInPounds = sc.nextDouble();

System.out.print("How long did you do the activity (in minutes) :");
timesInMins = sc.nextInt();

System.out.print("What is the MET value for your activity ? ");
metVal = sc.nextInt();
wtInKg = (wtInPounds * 0.453592);
caloriesBurned = ((metVal * 3.5 * wtInKg) / 200) * timesInMins;

// Displaying the output
System.out.print("The number of calories you have burned is :" + caloriesBurned);
} else if (choice == 'Y' || choice == 'y') {

while (true) {


// Getting the input entered by the user
System.out.print("How much do you weight in pounds :");
wtInPounds = sc.nextDouble();

System.out.print("How long did you do the activity (in minutes) :");
timesInMins = sc.nextInt();

System.out.print("What is the MET value for your activity ? ");
metVal = sc.nextInt();
wtInKg = (wtInPounds * 0.453592);

//calculating no of calories burned
caloriesBurned = ((metVal * 3.5 * wtInKg) / 200) * timesInMins;

//calculating total no of calories burned
totCalories += caloriesBurned;

count++;

//calculating average no of calories burned
avgColories = totCalories / count;

// Displaying the output
System.out.printf("The number of calories you have burned is : %.2f", caloriesBurned);

// Getting the character from the user 'Y' or 'y' or 'N' or 'n'
System.out.print(" Do you want to compute another calorie calculation (Y/N) ::");
char ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y')
continue;
else {

//Displaying total and average no of calories burned
System.out.println("Total No of Calories burned :" + totCalories);
System.out.println("Average No of Calories burned :" + avgColories);


System.out.println(" :: Program Exit ::");
break;
}

}

}

} else {
System.out.println(":: The Password you have entered is not correct ::");
}

}

}

__________________

Output:

Enter the Password: CAL2017
Do you want to compute the number of Calories burned ?(Y/N) Y
How much do you weight in pounds :150
How long did you do the activity (in minutes) :10
What is the MET value for your activity ? 5
The number of calories you have burned is : 59.53

Do you want to compute another calorie calculation (Y/N) ::Y
How much do you weight in pounds :170
How long did you do the activity (in minutes) :15
What is the MET value for your activity ? 5
The number of calories you have burned is : 101.21

Do you want to compute another calorie calculation (Y/N) ::N
Total No of Calories burned :160.741665
Average No of Calories burned :80.3708325

:: Program Exit ::

_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote