QuestionQuestion

Part 1:
Often times after a big meal, we may find ourselves considering how much we need to exercise to work off what we just ate. In this exercise we will actually compute it.
1) Oxygen consumption (VO2) can be used as an indicator of exercise intensity, which is closely tied to energy expenditure. In other words, VO2 can be used to approximate how many calories are burned during an activity.
The approximate VO2 for walking (on flat land) at a given speed (mph) can be computed as:
VO2 for walking = 2.68224 x speed + 3.5
The approximate VO2 for running (on flat land) at a given speed (mph) can be computed as:
VO2 for running = 5.36448 x speed + 3.5

2) The calorie burn rate (CBR) is the number of calories burned per minute when doing a certain activity. A simplified way to compute the CBR from VO2 and a person’s weight (lbs) is given by the formula:
CBR = (2.268 x 10‐3) x VO2 x weight

You need to write three (3) versions of a program that calculates how many minutes one needs to exercise to burn off a given amount of food they ate. To calculate the number of minutes required to burn off a given number of calories, simply divide the total calories by the calorie burn rate.
In the descriptions for PART A, PART B, and PART C, I use “chicken nuggets” as the food of choice. Assume that chicken nugget has 47 calories each. However, in your program you may use whatever type of food you want. Be sure to look up the amount of calories for that food type.

Disclaimer: Note that these calculations are simple approximations and do not account for all the different individual factors for each person. This exercise (pardon the pun) is intended to help students learn how to write computer programs, not to inform their decisions on how to take care of their physical health. Therefore, do not base any real‐life health or fitness program (pun intended) on these calculations.

PART A. Write a program FitnessPlanner_1 that asks the user to enter his/her weight in lbs, how many chicken nuggets were eaten, average walk speed in mph (typically 3 mph, which is a 20‐minute mile pace), and average run speed in mph (typically 6 mph, which is a 10‐minute mile pace). The program should then output how long the user needs to walk and how long the user needs to run in order to burn those chicken nuggets off.
Declare the calories of a chicken nugget as a global constant.

*** This Fitness Planner program will calculate how long ***
*** you need to exercise to burn off what you just ate. ***
What is your weight in pounds?
125
How many chicken nuggets did you eat?
20
What is your average WALKING speed in mph (3 is typical, a 20-min/mi pace)?
3
What is your average RUNNING speed in mph (6 is typical, a 10-min/mi pace)?
7
You need to walk for 287 minutes to burn off the 20 chicken nuggets you ate.
You need to run for 81 minutes to burn off the 20 chicken nuggets you ate.

PART B. Make a copy of the previous program and rename the class to FitnessPlanner_2. This time, before asking the user to enter a walking or running speed, ask the user if he/she prefers walking or running by asking the user to input “W” for walking or “R” for running. You then should only ask the user to enter the walking speed OR the running speed according to the user’s response to this query. Likewise, use the appropriate formula (for walking or for running).
When you read the letters w/W or r/R from the user, save them as strings. The method to read a string is next().
Example:
Scanner keyboard = new Scanner(System.in); System.out.println("Enter your gender: "); String gender = keyboard.next();

*** This Fitness Planner program will calculate how long ***
*** you need to exercise to burn off what you just ate. ***
What is your weight in pounds?
150
How many chicken nuggets did you eat?
12
Do you prefer walking or running (W or R)?
w
What is your average WALKING speed in mph (3 is typical, a 20-min/mi pace)?
2
You need to walk for 187 minutes to burn off the 12 chicken nuggets you ate.

PART C. Make a copy of the previous program and rename the class to FitnessPlanner_3. This time, instead of asking the user how many chicken nuggets he/she ate, ask for how much time the user will have to run or walk. Your program should then tell the user how many chicken nuggets he/she is allowed to eat without accumulating surplus calories, assuming they follow through with their exercise commitment. Also display how many calories will be burned.

*** This Fitness Planner program will calculate how much food ***
*** you can eat and how many calories you need to burn off. ***
What is your weight in pounds?
115
Do you prefer walking or running (W or R)?
R
What is your average RUNNING speed in mph (6 is typical, a 10-min/mi pace)?
8
How many minutes will you run?
30
Congratulations, you are allowed to eat 7 chicken nuggets.
You will burn off 363 calories later.

Part 2:

PART A: Write a program WhileLoops that uses while loops to perform the following steps:
1. Prompt the user to input two positive integers: firstNum and secondNum (firstNum must be smaller
than secondNum).
2. Output all the even numbers between firstNum and secondNum inclusive.
3. Output the sum of all the even numbers between firstNum and secondNum inclusive.
4. Output all the odd numbers between firstNum and secondNum inclusive.
5. Output the sum of all the odd numbers between firstNum and secondNum inclusive.

EXAMPLE OUTPUT:
Enter an integer:
3
Enter another integer larger than the first one: 10

Even numbers: 4 6 8 10 Sum of even numbers = 28 Odd numbers: 3 5 7 9 Sum of odd numbers = 24

PART B: Re‐write the program above using a for loop. Name the class ForLoops.

PART C: Write a program Digits that prompts the user to input a positive integer and then outputs the number reversed and the sum of the digits. For example, if the user enters the number 3456, then your program should output 6543 and the sum as 18.

Use a while loop.

EXAMPLE OUTPUT:
Enter an integer: 3478246
Number reversed: 6428743 Sum of digits: 34

You may assume the user enters a number smaller than the max int (2,147,483,647).

PART D: Write a program Stars that uses two nested for loops to output the pattern of stars shown below (note that there are no spaces in between stars).

EXAMPLE OUTPUT:
Enter an integer from 3 to 10: 7
*******
******
*****
****
***
**
*

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.Scanner;

public class FitnessPlanner_1 {

    public static void main(String[] args) {

       Scanner keyboard = new Scanner(System.in);

       System.out.println("*** This Fitness Planner program will calculate how long ***\n"
                + "*** you need to exercise to burn off what you just ate. ***\n");

       int weight, chicken, walking, running;

       System.out.println("What is your weight in pounds?");
       weight = keyboard.nextInt();
       System.out.println("How many chicken nuggets did you eat?");
       chicken = keyboard.nextInt();
       System.out.println("What is your average WALKING speed in mph (3 is typical, a 20-min/mi pace)?");
       walking = keyboard.nextInt();
       System.out.println("What is your average RUNNING speed in mph (6 is typical, a 10-min/mi pace)?");
       running = keyboard.nextInt();

       double cbr_walk = CBR(Vo2walking(walking), weight);
       double cbr_run = CBR(Vo2running(running), weight);
       double calories = chicken * 47.0;

       System.out.println("");
       System.out.println("You need to walk for " + Math.round(calories / cbr_walk)
                + " minutes to burn off the " + chicken
                + " chicken nuggets you ate.");
       System.out.println("You need to run for " + Math.round(calories / cbr_run)
                + " minutes to burn off the " + chicken
                + " chicken nuggets you ate.");
      
    }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$18.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats