home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Need some easy Java Help

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1727
Discussions: 200,950, Posts: 2,379,461, Members: 246,312
Old May 15th, 2004, 09:25 PM   Digg it!   #1 (permalink)
Gib
Member
 
Join Date: Mar 2002
Posts: 153
Need some easy Java Help

Hello,,, well I am learning java in school and the teacher is terrible, I have a hw assignment I have no idea how to do.

I have to finish writing the code to this program. the question is.

"The BMI applet computes a persons body mass index. BMI Applet is defined as the weight, in kg divided by the square of the height, expressed in meters. A fragment of the BMI applet is show below.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;

public class Bmi extends JApplet
implements ActionListener
{
JTextField inputLbs, inputInches, displayBmi;

public void init()
{
JLabel labelLbs = new JLabel("Weight (lbs):", SwingConstants.RIGHT);
inputLbs = new JTextField(5);
JLabel labelInches = new JLabel("Height (inches):", SwingConstants.RIGHT);
inputInches = new JTextField(5);
JLabel labelBmi = new JLabel("BMI = ", SwingConstants.RIGHT);
displayBmi = new JTextField(5);
displayBmi.setEditable(false);
JButton go = new JButton("Compute");
go.addActionListener(this);

Container c = getContentPane();
c.setBackground(Color.white);
JPanel p = new JPanel();
p.setLayout(new GridLayout(3, 2, 5, 5));
p.add(labelLbs);
p.add(inputLbs);
p.add(labelInches);
p.add(inputInches);
p.add(labelBmi);
p.add(displayBmi);
c.add(p, BorderLayout.CENTER);
c.add(go, BorderLayout.SOUTH);
}

public void actionPerformed(ActionEvent e)
{
int lbs = Integer.parseInt(inputLbs.getText());
int inches = Integer.parseInt(inputInches.getText());
double bmi = calculateBmi(lbs, inches);
DecimalFormat df = new DecimalFormat("00.0");
displayBmi.setText(df.format(bmi));
}

private double calculateBmi(int lbs, int inches)
{
< ... missing code >
}
}



I have to supply the missing code for the calculateBmi method, which takes weight in lbs and hight in inches as arguments and returns the body mass index...


ANY ideas here thanks/..
Gib is offline   Reply With Quote
Old May 17th, 2004, 03:26 AM     #2 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,177
Ok well I just had to rewrite this because I thought you had to create and actionPerformed method but apparently its already created!!!!

Actually this problem is very easy:

All you need to do is write a few lines of code that do all the calculations of the lbs and inches that the method is taking. For instance, if the bmi was found by adding lbs and inches then the code for that method would look as follows:

Code:
private double calculateBmi(int lbs, int inches)
{
      double total = lbs + inches;
      return total;
}


OR YOU CAN DO IT DIRECTLY...


private double calculateBmi(int lbs, int inches)
{
      return Double.parseDouble(lbs + inches);
}
Not too difficult. Just use that same methodology but you'll need to use the correct way to find the Bmi.
__________________
YAH! I knew you'd be jealous

Last edited by Tekk : May 19th, 2004 at 05:38 AM.
Tekk is offline   Reply With Quote
Old May 17th, 2004, 04:53 AM     #3 (permalink)
Retired mostly.
 
Join Date: Oct 2001
Location: Finland
Posts: 5,144
I don't know anything about java or your problem, but why are you using pounds and inches when it says at the top that it has to be kilograms and meters?
muno is offline   Reply With Quote
Old May 17th, 2004, 01:42 PM     #4 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,177
the teacher obviously wants them to do some conversion.
Tekk is offline   Reply With Quote
Old May 17th, 2004, 06:48 PM     #5 (permalink)
Gib
Member
 
Join Date: Mar 2002
Posts: 153
Thanks a lot Tekk
Gib is offline   Reply With Quote
Old May 18th, 2004, 12:09 AM     #6 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,177
no problem...lemme know if you need any more help
Tekk is offline   Reply With Quote
Old May 19th, 2004, 12:35 AM     #7 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
?

Last edited by Creosote : May 19th, 2004 at 01:13 AM.
Creosote is offline   Reply With Quote
Old May 19th, 2004, 12:47 AM     #8 (permalink)
Now in the nicer ghetto
 
butch81385's Avatar
 
Join Date: Jul 2003
Location: PA
Posts: 10,527
Send a message via AIM to butch81385
EDIT due to other EDIT. nothing to see here, move along people
__________________
I don't like signatures.

Last edited by butch81385 : May 19th, 2004 at 12:47 PM.
butch81385 is online now   Reply With Quote
Old May 19th, 2004, 02:05 AM     #9 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,177
who you replyin to butch?
Tekk is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ or Java? shawshank62 General Tech Discussion 17 February 25th, 2004 01:04 PM
Opera 7.21 brian0555 Applications and Operating Systems 7 November 2nd, 2003 11:36 AM
Looking for samples how to write an IRC client in C# gicio Webmastering and Programming 3 December 10th, 2002 01:39 AM
programmers wewtupdawg Applications and Operating Systems 4 August 14th, 2002 02:42 AM
Microsoft Java Virtual Machine Shoes General Tech Discussion 2 August 2nd, 2002 08:07 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
The disrespect of Obama by Russian .. (39)
Is It Just Me? (2941)
Making Health Care Worse (177)
Wireless Televisions. (12)
CPU fan stops spinning randomly (8)
windows 7 problem (7)
Regular Build (9)
radeon x850xt platinum & shader.. (6)
Is the PSU I received dead? (12)
Print spooler problem (15)
windows vista security holes (10)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Dept. of HS: NSA 'Helped' Develop V.. (16)
Recent Discussions
My monitor won't turn on after instal.. (1)
Regular Build (9)
Laptop with wireless problem. (3)
Internet Lost (3)
Virus advise (7)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
EVGA 9800 gtx help with finding a goo.. (10)
Modern Warfare 2: Who Bought It? (62)
windows vista security holes (10)
Point and Shoot Camera Suggestions. (4)
Multiple Restarts Required at Boot (2)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)
How to convert MP3's (4)
Wireless Televisions. (12)
Hp Artist Edition + Matching Bag (0)
Asus P4G8X Mobo (6)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)
windows 7 internet problem (5)
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)
Have you switched yet? (86)


All times are GMT -4. The time now is 01:09 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28