0

I am new in Java. I have to write a program that accept a person weight and display the number of Calories the person need in one day. A person needs 19 calories per pound of body weight, so the formula expressed in java is calories= bodyweight*19. Use JOptionPane claas method for input and output.
Here is my trial
import java.swing.*;
class HumanEnergy;
{
public static void main(String args[]);
{
float body_weight,calories;
String body_weight;
body_weight= JOptionPane.showInputDialog(“What is your body weight to be converted to Calories?”);
Change chan
body_weight=chan.nextFloat();
calories=body_weight*19;
body_weight= JOptionPane.showMessageDialog(null,”Your calories is”+calories);
}
}
}

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by jasimp
0

You have a few semi-colons where you don't need them and your Float body_weight and String body_weight have to have different names (say Float body_weight and String bodyWeight). Don't forget to change all other instances of your string variable to bodyWeight. You also have an extra bracket at the end. You will want to remove what I put in read. Those changes should help you figure out what else is wrong.

import java.swing.*;
class HumanEnergy;
{
public static void main(String args[]);
{
float body_weight,calories;
String bodyWeight;  // you can't have duplicate variable names
body_weight= JOptionPane.showInputDialog(“What is your body weight to be converted to Calories?”);
Change chan
body_weight=chan.nextFloat();
calories=body_weight*19;
body_weight= JOptionPane.showMessageDialog(null,”Your calories is”+calories);
}
}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.