1. Member
Join Date
Oct 2012
Location
uk
Posts
2
Rep Power
0

calculate a user’s weight loss based on the amount of exercise they take
user specifies full name and hours spent cycling, running and swimming
output first name, total calories burnt and pounds lost

cycling 200
running 475
swimming 275

person loses 1 pound for every 3500 calories burnt

iv been given headings i should use to help write the programme which are

//create Scanner for input
//declare constants for calories per activity and calories burnt
//prompt for name and input response
//prompt for hours spent exercising and input responses
//determine first name
//calculate calories burnt
//calculate weight loss
//output name, calories burnt and weight loss

now iv had a go at writing the programme but could someone please help me out with finishing any of the programme under the certain headings. heres what iv got so far -

(CODE)

import java.util.*;

public class weightloss
{
public static void main(String[] args)
{

//create Scanner for input
Scanner sc = new Scanner(System.in);

//declare constants for calories per activity and calories burnt
final int cycling_cal = 200;
final int running_cal = 475;
final int swimming_cal = 275;

//prompt for name and input response
System.out.print("Cycling Cals: ");
int cycling = sc.nextInt();
System.out.print("Running Cals: ");
int running = sc.nextInt();
System.out.print("Swimming Cals: ");
int swimming = sc.nextInt();

//promptfor hours spent exercising and input response
System.out.print("Cycling Hours: ");
int Cycling = sc.nextInt();
System.out.print("Running Hours: ");
int Running = sc.nextInt();
System.out.print("Swimming Hours: ");
int Swimming = sc.nextInt();
//determine first name

//calculate calories burnt
int total_cal = (Cycling * cycling_cal) + (Running * running_cal) + (Swimming * swimming_cal);

//calculate weight loss
int Pounds_lost = total_cal / 3500;

//output name, calories burnt and weight loss

System.out.println(total_cal + Pounds_lost);

(CODE)

What exactly are you stuck on? Does this compile? Also, please use the code tags when posting code, otherwise your code is pretty hard to read. You can go back and edit your post to add them.

3. Member
Join Date
Oct 2012
Location
uk
Posts
2
Rep Power
0

when it compiles it jus says cycle amount = 0??

the main thing i am stuck on is how i would enter variables as to add in firstName and fullName?

could you please tell me how to add the code tags so i can edit post

sorry im really new to this

To use code tags, just surround your code with [CODE]code here[/CODE]. Check out the forum rules or quote a post that uses them to see how to use them correctly.

Anyway, your code already reads in user input using a Scanner. Check out the API for Scanner for other useful functions.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•