212k views
5 votes
6) Create a java program The number of calories burned per hour during

bicycling, jogging, and swimming are 200, 475, and
275, respectively. A person loses 1 pound of weight for
each 3500 calories burned. Create a Java application that
allows the user to enter the number of hours spent in
each activity and then calculates the number of pounds
Lost

User Mud
by
6.5k points

1 Answer

2 votes

Answer: With the criteria you have listed, here's the code.

import java.util.Scanner;

public class CaloricExpenditure {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Enter the number of hours spent bicycling: ");

int hoursBicycling = scan.nextInt();

System.out.print("Enter the number of hours spent jogging: ");

int hoursJogging = scan.nextInt();

System.out.print("Enter the number of hours spent swimming: ");

int hoursSwimming = scan.nextInt();

int totalCalories = (hoursBicycling * 200) + (hoursJogging * 475) + (hoursSwimming * 275);

double poundsLost = totalCalories / 3500.0;

System.out.println("You have burned a total of " + totalCalories + " calories.");

System.out.println("This means you have lost " + poundsLost + " pounds.");

}

}

Step-by-step explanation:

The Scanner class is used in this software to ask the user to enter how many hours they spent doing each activity. The total amount of calories burned is then determined by dividing the caloric expenditure of each activity by the quantity of time spent engaging in that activity. The total amount of calories burned is then divided by 3500 to determine the number of pounds lost. The user sees the outcome in the console.

User AmbiguousX
by
7.6k points