Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By musclecode

Thread: BMI calculator

  1. #1
    snustad is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default BMI calculator

    Hey, I need some help with BMI calculator. I tryed to do something, but it doesn't work at all. Maybe someone you could make me a example for this (have more exercises, but I want to do them myself, just need an exaple :P). It pretty much should look like this:

    Ask:

    "Insert your name" -> and insert it on next line
    "Insert your length in cm" -> and insert it on next line
    "Insert your weight in kg" -> and insert it on next line

    Then output will tell:

    "Hello, (name)!
    With length (length) cm and weight (weight) kg your BMI is ...(I) .
    Info:
    * underweight is under 18,5;
    * normal is 18,5 - 24,9;
    * overweight is 25 - 29,9;
    * too fat is 30 - 39,9;
    * extra fat is over 40"

    I = K / (P/100)^2

    i = BMI
    K = weight
    p = length

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: BMI calculator

    Quote Originally Posted by snustad View Post
    Hey, I need some help with BMI calculator. I tryed to do something, but it doesn't work at all. Maybe someone you could make me a example for this (have more exercises, but I want to do them myself, just need an exaple :P). It pretty much should look like this:
    Come on now.

    We'll be glad to try to help you with your code, but please don't ask anyone to do this for you or to give you an example. Instead please show us what you've tried, and errors or misbehaviors your code may be causing and let's see if we can help y ou.

  3. #3
    snustad is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: BMI calculator

    Ok...heres what I have:
    import java.util.Scanner;


    public class Kt_2_1 {
    public static void main(String[] args) {
    Scanner scanner = new Scanner (System.in);
    double n, p, k, i;
    System.out.println("Insert your name:");
    n = scanner.nextDouble();
    System.out.println("Insert your length in cm:");
    p = scanner.nextDouble();
    System.out.println("Insert your weight in kg:");
    k = scanner.nextDouble();
    i = k / ((p / 100)*(p/100));
    System.out.printf("Hello: %n\n", );
    System.out.printf("With length: %p, cm and weight: %k, kg your BMI is: %i\n");
    System.out.printf("Info: \n");
    System.out.printf("* underweight is 18,5;: \n");
    System.out.printf("* normal is 18.5-24,9;: \n");
    System.out.printf("* overweight is 25-29,9;: \n");
    System.out.printf("* too fat is 30-39,9;: \n");
    System.out.printf("* extra fat is over 40;: \n");

    }
    }

  4. #4
    musclecode is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: BMI calculator

    I don't know how to use printf, but after modification looks right. And you can't use double type with name. It's String

    import java.util.Scanner;


    public class Kt_2_1 {
    public static void main(String[] args) {
    Scanner scanner = new Scanner (System.in);
    double p, k, i;
    String n;
    System.out.print("Insert your name:");
    n = scanner.nextLine();
    System.out.print("Insert your length in cm:");
    p = scanner.nextDouble();
    System.out.print("Insert your weight in kg:");
    k = scanner.nextDouble();
    scanner.close();
    i = k / ((p / 100)*(p/100));
    System.out.println("Hello: " +n );
    System.out.println("With length: " + p + " cm and weight: " +k+" kg your BMI is: " +i);
    System.out.println("Info: \n");
    System.out.println("* underweight is 18,5;: \n");
    System.out.println("* normal is 18.5-24,9;: \n");
    System.out.println("* overweight is 25-29,9;: \n");
    System.out.println("* too fat is 30-39,9;: \n");
    System.out.println("* extra fat is over 40;: \n");

    }
    }
    Last edited by musclecode; 11-29-2012 at 10:08 PM.
    snustad likes this.

  5. #5
    snustad is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Need help with + - * / calculator
    By Aconitum in forum New To Java
    Replies: 26
    Last Post: 08-04-2012, 08:13 PM
  2. calculator help
    By sirstroud in forum New To Java
    Replies: 0
    Last Post: 04-01-2012, 06:58 AM
  3. Need help with Calculator
    By Joshua4missions in forum New To Java
    Replies: 4
    Last Post: 12-10-2011, 03:44 AM
  4. calculator
    By rithish in forum AWT / Swing
    Replies: 10
    Last Post: 04-26-2011, 12:24 AM
  5. Calculator help.
    By madkidd02 in forum New To Java
    Replies: 2
    Last Post: 10-25-2008, 08:42 AM

Posting Permissions

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