IN JAVA
Methods*: Calorie estimator
Write a method ActivityCalories that takes a string indicating an activity (sit, walk, jog, bike, swim) and duration in minutes (integer), and returns the estimated calories expended (double). Calories per minute for a 150 lb person (source):
sit: 1.4 walk: 5.4 run: 13.0 bike: 6.8 swim: 8.7
If the input is sit 2, the output is
2.8
Hints:
Use an if-else statement to determine the calories per minute for the given activity.
Return the calories per minute times the minutes spent.
GIVEN CODE:
import java.util.Scanner;
public class Main {
/* Write your method here */
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int userMinutes;
String userActivity;
userActivity = scnr.next();
userMinutes = scnr.nextInt();
System.out.println(ActivityCalories(userActivity,
userMinutes));
}
}
#source code:
import java.util.Scanner;
public class Main {
public static double ActivityCalories(String userActivity,int userMinutes){
if(userActivity.equals("sit")){
return userMinutes*1.4;
}else if(userActivity.equals("walk")){
return userMinutes*5.4;
}else if(userActivity.equals("run")){
return userMinutes*13.0;
}else if(userActivity.equals("bike")){
return userMinutes*6.8;
}else if(userActivity.equals("swim")){
return userMinutes*8.7;
}
return 0;
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int userMinutes;
String userActivity;
userActivity = scnr.next();
userMinutes = scnr.nextInt();
System.out.println(ActivityCalories(userActivity, userMinutes));
}
}
#output:
#if you have any doubt or more information needed comment below..i will respond as possible as soon...thanks...
Get Answers For Free
Most questions answered within 1 hours.