473,698 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with a Java Program

1 New Member
--------------------------------------------------------------------------------

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 3293
dmjpro
2,476 Top Contributor
--------------------------------------------------------------------------------

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.Scann er;
import java.lang.Math;


public class Hw05{

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

int weight= myScanner.nextI nt();
System.out.prin t( "Enter your height (in inches): " );

int height = myScanner.nextI nt();

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

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


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


if (BMI >= 39.5) {
System.out.prin tln("You are Severely Obese");
System.out.prin tln("You should try to lose " + Math.round(idea l*100)/100);
} else if (BMI >= 29.5) {
System.out.prin tln("You are Obese");
System.out.prin tln("You should try to lose " + Math.round(idea l*100)/100);
} else if (BMI >= 24.9) {
System.out.prin tln("You are Overweight");
System.out.prin tln("You should try to lose " + Math.round(idea l*100)/100);
} else if (BMI <= 19.5) {
System.out.prin tln("You are Underweight");
System.out.prin tln("You should try to gain " + Math.round(idea l*100)/100);
} else {
System.out.prin tln("You are Normal");
System.out.prin tln("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*hei ght)/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
3580
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 automatically send data to the other program but for some reason the child hangs. The first piece of info prompted for is an integer, and the second prompt asks for a floating number. I am trying to send the program "3\n" to satisfy the first...
3
2756
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: Class.forName("com.ibm.db2.jcc.DB2Driver"); Connection connection = DriverManager.getConnection( "jdbc:db2:<database-name>", "<user>", "<password>" );
7
1460
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
2219
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 CLASSPATH variable. The program runs normally when I launch it in a unix shell. Now, I want to launch this JAVA program in a PHP program with system() function for example. I have an Apache server with PHP 4 who runs. The
1
3134
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 part just explains a check digit.. i think this part in my program is alright These barcodes actually have four parts: a tall line as the first bar, a series of tall and short lines corresponding to the digits in the ZIP code, a check digit,...
0
7113
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 the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment. Here is the assignment: Modify the Inventory program by adding a button to the GUI that allows the user to move...
6
2285
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 like to delete one record in database, it always shows "record not found" in my program, even if the data has been deleted. I tried to used function for each choices. But the compiler showed that we can't used function in static void. Is there...
3
4480
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 of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional attribute, and the restocking fee. Here is my Inventory program from 1 to 3: package...
0
2434
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 org/apache/axis The following is what i need to do but am unable to do //////////////////////////////////////////////////////////////////////////////////////////// set classpath where the below jars are located.... axis.jar commons-discovery.jar
0
10766
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.