Modify the code at the bottom so that it includes the following: prompts the use
ID: 669310 • Letter: M
Question
Modify the code at the bottom so that it includes the following:
prompts the user for
Their name
Weight
Basketball hours
Running hours
Sleeping hours
Displays the information and nicely formating, including any floating point number to two decimal places.
public static void main(String[] args)
{
double weightInPounds = 170;
double timeRunning = 30;
double timeBasketball = MINUTE_PER_HOUR * 1;
double timeSleeping = MINUTE_PER_HOUR * 8;
double weightInKg = weightInPounds / POUNDS_PER_KG;
String name = "Ian";
double runningCalories = 0.0175 * RUNNING_METS * weightInKg * timeRunning;
double basketballCalories = 0.0175 * BASKETBALL_METS * weightInKg * timeBasketball;
double sleepingCalories = 0.0175 * SLEEPING_METS * weightInKg * timeSleeping;
double totalCalories = runningCalories + basketballCalories + sleepingCalories;
System.out.println("Welcome to the calorie calculator.");
System.out.println("This program will calculate calories burned for " + name + " who weights " + weightInPounds + " pounds.");
System.out.println(name + " burned an estimated " + runningCalories + " calories running.");
System.out.println(name + " burned an estimated " + basketballCalories + " calories playing basketball.");
System.out.println(name + " burned an estimated " + sleepingCalories + " calories sleeping.");
System.out.println(name + " expended at total of: " + totalCalories);
}
}
Explanation / Answer
public static void main(String[] args)
{
double weightInPounds = 170;
double timeRunning = 30;
double timeBasketball = MINUTE_PER_HOUR * 1;
double timeSleeping = MINUTE_PER_HOUR * 8;
double weightInKg = weightInPounds / POUNDS_PER_KG;
String name = "Ian";
double runningCalories = 0.0175 * RUNNING_METS * weightInKg * timeRunning;
double basketballCalories = 0.0175 * BASKETBALL_METS * weightInKg * timeBasketball;
double sleepingCalories = 0.0175 * SLEEPING_METS * weightInKg * timeSleeping;
double totalCalories = runningCalories + basketballCalories + sleepingCalories;
System.out.println("Welcome to the calorie calculator.");
System.out.println("This program will calculate calories burned for " + name + " who weights " + weightInPounds + " pounds.");
System.out.println(name + " burned an estimated " + runningCalories + " calories running.");
System.out.println(name + " burned an estimated " + basketballCalories + " calories playing basketball.");
System.out.println(name + " burned an estimated " + sleepingCalories + " calories sleeping.");
System.out.println(name + " expended at total of: " + totalCalories);
System.out.println(“their name=” +name);
System.out.println(“weight= “+weightInPounds);
System.out.println(“basketball hours=” +timeBasketball);
System.out.println(“running hours =“+runningCalories);
System.out.println(“Sleeping hours =“+sleepingCalories);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.