473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Need help with a Java Program

--------------------------------------------------------------------------------

First,

Hello eveyone and I am new to Java.

I am trying to create a Java program that will calculate a person BMI based on user input of weight (in pounds) and heigh (in inches) and then display what the BMI is and give the a message that tells them where they fit plus I want to then be able to tell them how much weight they need to loss (or gain if underweight) to attain a normal BMI (25).

I have got it all to work except then last part (calculating how much they need to gain or loss to obtain a 25 BMI).

Here is the code I have so far:
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3.  
  4.  
  5. public class Hw05{
  6.  
  7. public static void main (String args[]) {
  8. Scanner myScanner= new Scanner (System.in);
  9. System.out.print( "Enter your weight (in pounds): " );
  10.  
  11. int weight= myScanner.nextInt();
  12. System.out.print( "Enter your height (in inches): " );
  13.  
  14. int height = myScanner.nextInt(); 
  15.  
  16. double BMI = 704.5 * weight/(height*height); 
  17.  
  18. System.out.println("Your Body Max Index = " + Math.round(BMI*100)/100);
  19.  
  20.  
  21. double ideal = 704.5 * 100/(height*height);
  22.  
  23.  
  24. if (BMI >= 39.5) {
  25. System.out.println("You are Severely Obese");
  26. System.out.println("You should try to lose " + Math.round(ideal*100)/100);
  27. } else if (BMI >= 29.5) {
  28. System.out.println("You are Obese");
  29. System.out.println("You should try to lose " + Math.round(ideal*100)/100);
  30. } else if (BMI >= 24.9) {
  31. System.out.println("You are Overweight");
  32. System.out.println("You should try to lose " + Math.round(ideal*100)/100);
  33. } else if (BMI <= 19.5) {
  34. System.out.println("You are Underweight");
  35. System.out.println("You should try to gain " + Math.round(ideal*100)/100);
  36. } else {
  37. System.out.println("You are Normal");
  38. System.out.println("You are maintaining a healthy weight!");
  39. }
  40.  
  41. }
  42. }


PLEASE HELP

Mel

--------------------------------------------------------------------------------
Oct 8 '07 #1
1 3277
dmjpro
2,476 2GB
--------------------------------------------------------------------------------

First,

Hello eveyone and I am new to Java.

I am trying to create a Java program that will calculate a person BMI based on user input of weight (in pounds) and heigh (in inches) and then display what the BMI is and give the a message that tells them where they fit plus I want to then be able to tell them how much weight they need to loss (or gain if underweight) to attain a normal BMI (25).

I have got it all to work except then last part (calculating how much they need to gain or loss to obtain a 25 BMI).

Here is the code I have so far:
import java.util.Scanner;
import java.lang.Math;


public class Hw05{

public static void main (String args[]) {
Scanner myScanner= new Scanner (System.in);
System.out.print( "Enter your weight (in pounds): " );

int weight= myScanner.nextInt();
System.out.print( "Enter your height (in inches): " );

int height = myScanner.nextInt();

double BMI = 704.5 * weight/(height*height);

System.out.println("Your Body Max Index = " + Math.round(BMI*100)/100);


double ideal = 704.5 * 100/(height*height);


if (BMI >= 39.5) {
System.out.println("You are Severely Obese");
System.out.println("You should try to lose " + Math.round(ideal*100)/100);
} else if (BMI >= 29.5) {
System.out.println("You are Obese");
System.out.println("You should try to lose " + Math.round(ideal*100)/100);
} else if (BMI >= 24.9) {
System.out.println("You are Overweight");
System.out.println("You should try to lose " + Math.round(ideal*100)/100);
} else if (BMI <= 19.5) {
System.out.println("You are Underweight");
System.out.println("You should try to gain " + Math.round(ideal*100)/100);
} else {
System.out.println("You are Normal");
System.out.println("You are maintaining a healthy weight!");
}

}
}



PLEASE HELP

Mel

--------------------------------------------------------------------------------

Good try !
You should try to use Code tags first to make your thread more readable :-)
Look ..... !
I think you are using right formula to get BMI....
BMI = 704.5 * weight/(height*height);
Now weight = (BMI*height*height)/704.5
Now calculate required BMI.
req_BMI = (25~current_BMI)
So for that BMI calculate the weight (to be gained or lost).

Debasis Jana.
Oct 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chad | last post by:
I need my java program to exec an external .exe file, but the problem is that this program being exec()'ed prompts the user for two pieces of information. I am trying to get my java program to...
3
by: rjaw | last post by:
Hi there, using the udb-type2-driver on z/OS DB version 7, we have a problem getting the connection to the database. The small program we use looks like this: ...
7
by: fidlee | last post by:
i am new to learning jython... i just tried compiling a small piece of code that is given below: def fac(x) if x<=1:return 1 return x*fac(x-1) on
1
by: sylsau | last post by:
Hello, I wrote a JAVA program which uses the JAVA API JDOM 1.0 (of this site www.jdom.org) I put the archive jdom.jar in the directory /usr/share/java/jdom.jar and I added this path in the...
1
by: Unebrion | last post by:
Alright im working on a program that prints out user imput in a frame, along with a barcode.. it is like the front of an envelope. Here is the description for the program. This...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
6
crystal2005
by: crystal2005 | last post by:
Hello guys, I'm a beginner in Java application programming. I started to write a Java application in which link to MS Access database. I encountered a problem in deletion function. E.g. I would...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
0
by: Siyodia | last post by:
This is a java program which i need to run facing compilation error Its consuming a third party web service method I have the supported files(folder) which contain necessary class files...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.