Question: USING ECLIPSE IDE JAVA!!!! NEED OUPUT TO LOOK HOW IT LOOKS ON THIS PICTURE BUT OUTPUT IS NOT SHOWING THE BMI CALCULATION NOR THE BUTTON

USING ECLIPSE IDE JAVA!!!! NEED OUPUT TO LOOK HOW IT LOOKS ON THIS PICTURE BUT OUTPUT
IS NOT SHOWING THE BMI CALCULATION NOR THE BUTTON THAT SAYS "CALCULATE BMI"
CAN SOMEONE PLS HELP FIX CODE
package edu.pupr.BMIClaculator;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class BMIClaculator{
public static void main(String[] args){
JFrame frame = new JFrame("BMI Calculator");
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
placeComponents(panel);
frame.setVisible(true);
}
private static void placeComponents(JPanel panel){
panel.setLayout(null);
JLabel userLabel = new JLabel("BMI");
userLabel.setBounds(10,20,80,25);
panel.add(userLabel);
JLabel weightLabel = new JLabel("How many pounds you weigh?");
weightLabel.setBounds(10,50,200,25);
panel.add(weightLabel);
JTextField weightText = new JTextField(20);
weightText.setBounds(220,50,50,25);
panel.add(weightText);
JLabel heightLabel = new JLabel("What is your height in inches?");
heightLabel.setBounds(10,80,200,25);
panel.add(heightLabel);
JTextField heightText = new JTextField(20);
heightText.setBounds(220,80,50,25);
panel.add(heightText);
JLabel bmiLabel = new JLabel("Your BMI is");
bmiLabel.setBounds(10,110,80,25);
panel.add(bmiLabel);
JLabel categoryLabel = new JLabel("(Obese)");
categoryLabel.setBounds(10,140,200,25);
panel.add(categoryLabel);
JButton calculateButton = new JButton("Calculate BMI");
calculateButton.setBounds(10,170,150,25);
panel.add(calculateButton);
calculateButton.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
try {
double weight = Double.parseDouble(weightText.getText());
double height = Double.parseDouble(heightText.getText());
double bmi = calculateBMI(weight, height);
bmiLabel.setText("Your BMI is: "+ bmi);
categoryLabel.setText(getBMICategory(bmi));
} catch (NumberFormatException ex){
JOptionPane.showMessageDialog(panel, "Please enter valid numerical values for weight and height.", "Input Error", JOptionPane.ERROR_MESSAGE);
}
}
});
}
private static double calculateBMI(double weight, double height){
return (weight /(height * height))*703;
}
private static String getBMICategory(double bmi){
if (bmi 18.5){
return "Underweight";
} else if (bmi >=18.5 && bmi 24.9){
return "Normal Weight";
} else if (bmi >=25 && bmi 29.9){
return "Overweight";
} else {
return "Obese";
}
}
}
 USING ECLIPSE IDE JAVA!!!! NEED OUPUT TO LOOK HOW IT LOOKS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!