Texts: I attempted this but I keep getting an error for whitespace. Could someone fix this for me?
Problem: The following equation estimates the average calories burned for a person when exercising, which is based on a scientific journal article (source):
Calories = ((Age x 0.2757) + (Weight x 0.03295) + (Heart Rate x 1.0781) - 75.4991) x Time / 8.368
Write a program using inputs age (years), weight (pounds), heart rate (beats per minute), and time (minutes), respectively. Output the average calories burned for a person.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
System.out.printf("%.2f", yourValue);
Ex: If the input is:
49 155 148 60
the output is:
Calories: 736.21 calories
The code:
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
/* Type your code here. */
Scanner input = new Scanner(System.in);
int age = input.nextInt();
int weight = input.nextInt();
int heartRate = input.nextInt();
int time = input.nextInt();
double calories = ((age * 0.2757) + (weight * 0.03295) + (heartRate * 1.0781) - 75.4991) * time / 8.368;
System.out.printf("Calories: %.2f calories", calories);
}
}
1. Compare output
015
Output is nearly correct, but whitespace differs. See highlights below:
Special character legend
Input: 49 155 148 60
Your output: Calories: 736.21/calories
Expected output: Calories: 736.21 calories
2. Compare output
0/5
Output is nearly correct, but whitespace differs. See highlights below:
Special character legend
Input: 25 130 120 45
Your output: Calories: 349.81calories
Expected output: Calories: 349.81 calories