why calculation(BMI) is not working.... please help me...
-
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);
-
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);
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 justBMI < 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.