java help please


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: java help please

  1. #1
    Join Date
    May 2004
    Posts
    1

    java help please

    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/..

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    well what exactly don't you understand? The formula for the calculation is given at the top. I'm sure you can write that down, and converting it into java isn't too hard at all. You need to write down the formula in java, using the variables that are supplied as parameters to the method. Then you simply need to return the result.

  3. #3
    Join Date
    Feb 2004
    Posts
    808
    he's blaming his teacher for his inability to go to lectures/not drink so much/learn some java/get enthusiatic enough (about the education that (s)he's paying for) to learn on his/her own..

    or something :/

    java isnt hard, even if your teacher sucks.. youre probably just telling yourself that because youre finding it hard, and hence, switching off your brain when in lectures.. I dont doubt that some teachers do suck, very much.. but that shouldnt hold you up any, because YOU are doing the learning, and there are other resources than your teacher to rely on.. when you start work your boss isnt going to spoon feed you everything you need to know about the job, so best get some research done, get some books out of the library (or buy some) about learning java, and sit down and really think about it..
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center