Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. why calculation(BMI) is not working.... please help me...

why calculation(BMI) is not working.... please help me...

Scheduled Pinned Locked Moved Java
javacomdockerhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11377727
    wrote on last edited by
    #1

    Greetings, everything in this code works except when the i input the weight and height the result is not shown in the textbox (v_text).. please help me

    package bmicalculator;

    import static com.sun.corba.se.impl.orbutil.CorbaResourceUtil.getText;
    import java.lang.*;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.GridLayout;
    import java.awt.event.*;
    import java.io.*;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.PrintWriter;
    import java.io.IOException;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.JPanel;
    import javax.swing.JFileChooser;
    import java.awt.Container;
    import java.beans.PropertyChangeListener;
    import java.beans.PropertyChangeEvent;

    public class BMICalculator extends JFrame implements ActionListener, PropertyChangeListener
    {

    /\*\*
     \* Set up my GUI
     \* 
     \*/
    JPanel p\_format;
    JPanel p\_text;
    JLabel f\_name;
    JLabel height;
    JLabel weight;
    
    JTextField n\_text;
    JFormattedTextField h\_text;
    JFormattedTextField w\_text;
    JFormattedTextField v\_text;
    JTextField r\_text;
    JTextArea a\_text;
    
    JButton v\_bmi;
    JButton result;
    JButton r\_done;
    JButton r\_save;
    JButton r\_reset;
    JButton f\_open;
    JFileChooser chooser = new JFileChooser();
    
    String Height, Weight;
    double BMI;
    static String output = "Results";
    static int jopIcon = JOptionPane.QUESTION\_MESSAGE;
    boolean bFlag = true; //state, true means no exception
    
    Font font;
    static int f\_size = 16; 
    static int style = Font.PLAIN;
    static String font\_name = " Harrington ";
    
    double number1;
    double number2;
    
    
    public BMICalculator (String s)
    {
        super(s);
    	font = new Font(font\_name, style, f\_size);
    	getContentPane().setLayout(new GridLayout(1,2));
    	p\_format = new JPanel();
    	p\_text = new JPanel();
                
                
                //First Panel////////////////////////////////////
                
                p\_text.setLayout(null);
                
                f\_name = new JLabel(" Name: ");
                f\_name.setSize(120,60);
                f\_name.setLocation(30, 30);
                f\_name.setForeground(Color.DARK\_GRAY);
                
                n\_text = new JTextField(40);
    	n\_text.setSize(120,60);
    	n\_text.setLocation(70,30);
    
    L 1 Reply Last reply
    0
    • U User 11377727

      Greetings, everything in this code works except when the i input the weight and height the result is not shown in the textbox (v_text).. please help me

      package bmicalculator;

      import static com.sun.corba.se.impl.orbutil.CorbaResourceUtil.getText;
      import java.lang.*;
      import java.awt.Color;
      import java.awt.Font;
      import java.awt.GridLayout;
      import java.awt.event.*;
      import java.io.*;
      import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileReader;
      import java.io.FileWriter;
      import java.io.PrintWriter;
      import java.io.IOException;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.JPanel;
      import javax.swing.JFileChooser;
      import java.awt.Container;
      import java.beans.PropertyChangeListener;
      import java.beans.PropertyChangeEvent;

      public class BMICalculator extends JFrame implements ActionListener, PropertyChangeListener
      {

      /\*\*
       \* Set up my GUI
       \* 
       \*/
      JPanel p\_format;
      JPanel p\_text;
      JLabel f\_name;
      JLabel height;
      JLabel weight;
      
      JTextField n\_text;
      JFormattedTextField h\_text;
      JFormattedTextField w\_text;
      JFormattedTextField v\_text;
      JTextField r\_text;
      JTextArea a\_text;
      
      JButton v\_bmi;
      JButton result;
      JButton r\_done;
      JButton r\_save;
      JButton r\_reset;
      JButton f\_open;
      JFileChooser chooser = new JFileChooser();
      
      String Height, Weight;
      double BMI;
      static String output = "Results";
      static int jopIcon = JOptionPane.QUESTION\_MESSAGE;
      boolean bFlag = true; //state, true means no exception
      
      Font font;
      static int f\_size = 16; 
      static int style = Font.PLAIN;
      static String font\_name = " Harrington ";
      
      double number1;
      double number2;
      
      
      public BMICalculator (String s)
      {
          super(s);
      	font = new Font(font\_name, style, f\_size);
      	getContentPane().setLayout(new GridLayout(1,2));
      	p\_format = new JPanel();
      	p\_text = new JPanel();
                  
                  
                  //First Panel////////////////////////////////////
                  
                  p\_text.setLayout(null);
                  
                  f\_name = new JLabel(" Name: ");
                  f\_name.setSize(120,60);
                  f\_name.setLocation(30, 30);
                  f\_name.setForeground(Color.DARK\_GRAY);
                  
                  n\_text = new JTextField(40);
      	n\_text.setSize(120,60);
      	n\_text.setLocation(70,30);
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Too much code, so I'm not going to look through all of it. This caught my attention as "obviously wrong" though: else if (BMI <= 25 || BMI < 28.9) that's really just BMI < 28.9, the other part is redundant. It's probably meant to be >= 25? But then the logic also doesn't quite work, because clearly there is a gap between 25 and 24.9, a rather large gap at that - if I counted them correctly, there are 28147497671065 doubles that have a value strictly between 24.9 and 25, which implies that almost all of them won't be generated by sensible inputs, but see for example 90kg / 1.90m2. Also, BMICalculate does some unexpected things, taking nice arguments and then ignoring them and pulling its values from some control.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups