Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2012
    Location
    uk
    Posts
    2
    Rep Power
    0

    Default java programme - one of my first and im struggling please help

    ive been given a task and im struggling, please help

    heres the task

    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

    task cals burnt per hour
    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)

    PLEASE ADVISE ON HOW TO COMPLETE UNFINISHED PARTS / HEADINGS AND ADVISE ME ON ANY MISTAKES MADE, THANYOU SO MUCH
    Last edited by please help me; 10-12-2012 at 06:23 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,882
    Rep Power
    8

    Default Re: java programme - one of my first and im struggling please help

    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.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: java programme - one of my first and im struggling please help

    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

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,882
    Rep Power
    8

    Default Re: java programme - one of my first and im struggling please help

    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.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Need help with first Java programme.. Very new!
    By xxdave in forum New To Java
    Replies: 3
    Last Post: 11-22-2011, 04:46 PM
  2. Struggling with OnKeyPressed Event in java
    By Camzie in forum NetBeans
    Replies: 2
    Last Post: 12-01-2009, 07:58 AM
  3. Struggling with java .ini files
    By Camzie in forum NetBeans
    Replies: 6
    Last Post: 11-24-2009, 03:13 PM

Posting Permissions

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