Re: having a little trouble
Please explain what the problem is. post any error messages you get.
Show the program's output and explain what is wrong and show what it should be.
Re: having a little trouble
this is the list of errors, the window opens, i enter the information, click the button and this is the result. what it should do instead of all this is to calculate the information and post the result
the problems are on lines 29 and 31 if you copy and paste the entire thing to an ide
run:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
at AccurateBMI.actionPerformed(AccurateBMI.java:35)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.jav a:6504)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3321)
at java.awt.Component.processEvent(Component.java:626 9)
at java.awt.Container.processEvent(Container.java:222 9)
at java.awt.Component.dispatchEventImpl(Component.jav a:4860)
at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
at java.awt.Component.dispatchEvent(Component.java:46 86)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4422)
at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713 )
at java.awt.Component.dispatchEvent(Component.java:46 86)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:707)
at java.awt.EventQueue.access$000(EventQueue.java:101 )
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 677)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:90)
BUILD SUCCESSFUL (total time: 26 seconds)
Re: having a little trouble
Quote:
Uncompilable source code - Erroneous tree type: <any>
at AccurateBMI.actionPerformed(AccurateBMI.java:35)
What code is at line 35 in AccurateBMI.java?
Can you compile your program and get errors from the compiler? The IDE seems to hide what the error is.
Re: having a little trouble
line 29 = line 35 - comments
line 29(35): totalBMI.setText("Your more accurate BMI is: " + bmiTot); //error part underlined
line 31(37): if (gender == T | gender == t){ //problems underlined
Re: having a little trouble
What are the errors?
Common errors would be the variables are NOT defined.
Is bmiTot defined? And is its definition in scope where you are using it?
gender is a String. You need to use the equals() method to test if its contents is equal to the contents of the T variable and the t variable.
Are T and t variables? Where are they defined? Should the be Strings? If so put them in "s
Re: having a little trouble
This is editted and fixed one problem but created another
Code :
public void actionPerformed(ActionEvent event) {
String gender = trueFalse.getText();
double pounds = Double.parseDouble(heavy.getText());
double height = Double.parseDouble(inches.getText());
double wrist = Double.parseDouble(circum.getText());
double num1 = height*height;
double bmi = (pounds/num1)*703;
//totalBMI.setText("Your more accurate BMI is: " + bmiTot);
//totalBMI.setText("Your more accurate BMI is: " + );
double bmiTot = if (gender == () | gender == ()){
if (height >= 65 && wrist >= 7.5){
bmiTot = bmi*.9;
}else {
bmiTot = bmi;
}
}else {
if (height >= 65 && wrist >= 6.5 || height > 62 && height < 65 && wrist >= 6.25 || height <= 62 && wrist > 5.75){
bmiTot = bmi*.9;
}else {
bmiTot = bmi;
}
};
totalBMI.setText("Your more accurate BMI is: " + bmiTot);
double bmiTot = if (gender == () | gender == ()){
now gives 3 errors stating illegal start of statement
the "t" and "T" are options for a string entry
Re: having a little trouble
double bmiTot = if (gender == () | gender == ()){
If statements do not return a value. So what value are your expecting to be assigned to the bmiTot variable?
Re: having a little trouble
bmiTot is supposed to return the result of of the if statement's calculation
if i enter it like this:
double bmiTot = //then my error is here (illegal start of expression)
if (gender.equals(T) | gender.equals(t)){
if (height >= 65 && wrist >= 7.5){
bmiTot = bmi*.9;
}else {
bmiTot = bmi;
}
}else {
if (height >= 65 && wrist >= 6.5 || height > 62 && height < 65 && wrist >= 6.25 || height <= 62 && wrist > 5.75){
bmiTot = bmi*.9;
}else {
bmiTot = bmi;
}
};
totalBMI.setText("Your more accurate BMI is: " + bmiTot);
Re: having a little trouble
Quote:
illegal start of expression
What expression do you have to the right of the = ?
Give bmiTot an initial value of 0.0
Re: having a little trouble
nevermind. I figured it out, my space provided wasn't big enough.
thank you guys so much for helping me with this!!!
here is the completed code if anyone wants it for anything
Code :
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class AccurateBMI extends JComponent implements ActionListener {
String t;
String T;
JFrame frame = new JFrame("A More Accurate BMI Calculator");
Container content = frame.getContentPane();
JLabel male = new JLabel();
JTextField trueFalse = new JTextField();
JLabel weight = new JLabel();
JTextField heavy = new JTextField();
JLabel height = new JLabel();
JTextField inches = new JTextField();
JLabel wrist = new JLabel();
JTextField circum = new JTextField();
JButton calcBMI = new JButton();
JLabel totalBMI = new JLabel();
public static void main(String[] args) {
AccurateBMI application = new AccurateBMI();
}
public void actionPerformed(ActionEvent event) {
String gender = trueFalse.getText();
double pounds = Double.parseDouble(heavy.getText());
double height = Double.parseDouble(inches.getText());
double wrist = Double.parseDouble(circum.getText());
double num1 = height*height;
double bmi = (pounds/num1)*703;
//totalBMI.setText("Your more accurate BMI is: " + bmiTot);
//totalBMI.setText("Your more accurate BMI is: " + );
double bmiTot = 0.0;
if (gender.equals(T) | gender.equals(t)){
if (height >= 65 && wrist >= 7.5){
bmiTot = bmi*.9;
}else {
bmiTot = bmi;
}
}else {
if (height >= 65 && wrist >= 6.5 || height > 62 && height < 65 && wrist >= 6.25 || height <= 62 && wrist > 5.75){
bmiTot = bmi*.9;
}else {
bmiTot = bmi;
}
};
totalBMI.setText("Your more accurate BMI is: " + bmiTot);
}
public AccurateBMI() {
content.setBackground(Color.white);
content.setLayout(null);
content.setForeground(Color.yellow);
content.setFont(new Font("Arial", Font.ITALIC, 14));
content.add(this);
male.setText("You are a male. T or F: ");
male.setLocation(5,5);
male.setSize(300,30);
content.add(male);
trueFalse.setText("");
trueFalse.setLocation(310,5);
trueFalse.setSize(50,30);
content.add(trueFalse);
trueFalse.addActionListener(this);
weight.setText("How much do you weigh in pounds?");
weight.setLocation(5,50);
weight.setSize(300,30);
content.add(weight);
heavy.setText("");
heavy.setLocation(310,50);
heavy.setSize(50,30);
content.add(heavy);
heavy.addActionListener(this);
height.setText("Please enter your height in inches: ");
height.setLocation(5,95);
height.setSize(300,30);
content.add(height);
inches.setText("");
inches.setLocation(310,95);
inches.setSize(50,30);
content.add(inches);
inches.addActionListener(this);
wrist.setText("How many inches around is your wrist? ie: 7.25 ");
wrist.setLocation(5,140);
wrist.setSize(300,30);
content.add(wrist);
circum.setText("");
circum.setLocation(310,140);
circum.setSize(50,30);
content.add(circum);
circum.addActionListener(this);
calcBMI.setText("Calculate");
calcBMI.setLocation(130,180);
calcBMI.setSize(100,30);
content.add(calcBMI);
calcBMI.addActionListener(this);
totalBMI.setText(" ");
totalBMI.setLocation(100,220);
totalBMI.setSize(200,30);
content.add(totalBMI);
frame.setLocation(0,0);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(385,300);
frame.setVisible(true);
}
}