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);
}
}
}

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);
}
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.