import javax.swing.JOptionPane;


public class conversionweight
{
public conversionweight()
{
String ans;
ans = JOptionPane.showInputDialog(null, "Enter Weight in Stone.Pounds" );
double stones = Double.parseDouble(ans);
double pounds = 14 * stones;
double kilos = 0.45359237 * pounds;



JOptionPane.showMessageDialog(null, " weight in Kilos = " + kilos);


System.exit(0);
}
}

my task was to produce a program which converts stone.pounds into kilograms.
i have got this code so farr i was just wondering if there is any way of splitting up the "ans" so that i can just multiple the stones by 14 then add the pounds rather then mutliplying the stones.pounds altogether by 14.

1) you can make custom dialog that takes two variables instead of one
2) request stones with first dialog and then request pounds in second dialog and work with them

That is if I correctly interpreted the part "splitting up the "ans" so that i can just multiple the stones by 14 then add the pounds" as reading two variables and process them

How would i go about doing this?
thanks

The second option will be easier for you.
Basicaly it is same as you have now, but you will add another dialog for pound amount to be add after stones dialog. Also you should apply some validating mechanizm to check if entered data are in valid form that you can process

The second option will be easier for you.
Basicaly it is same as you have now, but you will add another dialog for pound amount to be add after stones dialog. Also you should apply some validating mechanizm to check if entered data are in valid form that you can process

Thanks for that, done it and works a treat

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.