The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Using methods improperly

I just recently started to learn about methods. I'm not that good with them nor do I fully understand them. This program I am writing is a simple program its asks the user if they want to convert pounds to kilograms or kilograms to pounds. In this assignment we are required to have 4 methods: The main method, P2k(pounds to kilos method), K2P, and a method that prints the results. I am not sure how to properly call the methods into the main method Here is my code if anyone can help me out.

Re: Using methods improperly

So i have the conversions working but I think im doing it without calling the printresults method could anyone tell me how i would incorporate the printresults method into my calculations, also when is displays it has to say 50 pounds but it says 50.0 pounds, should i change it to an int?

WEIGHT CONVERSION
1.Pounds to kilograms
2.Kilograms to pounds
Please select the type of conversion you would like to make:1
Please enter the pounds:50
50.0 pounds is 22.686025408348456 kilograms.BUILD SUCCESSFUL (total time: 6 seconds)

Kilos to pounds :WEIGHT CONVERSION
1.Pounds to kilograms
2.Kilograms to pounds
Please select the type of conversion you would like to make:2
Please enter the kilograms:50
50.0kilograms is 110.2 pounds. BUILD SUCCESSFUL (total time: 3 seconds)

and the last one choosing neither :
WEIGHT CONVERSION
1.Pounds to kilograms
2.Kilograms to pounds
Please select the type of conversion you would like to make:-1
Error: Invalid conversion selection,Please run the program again.
BUILD SUCCESSFUL (total time: 2 seconds)

These are the results :
WEIGHT CONVERSION
1.Pounds to kilograms
2.Kilograms to pounds
Please select the type of conversion you would like to make:1
Please enter the pounds:50
0.0 pounds is 22.686025408348456 kilograms.0.0kilograms is 22.686025408348456 pounds. BUILD SUCCESSFUL (total time: 3 seconds)

Kilos to pounds:
WEIGHT CONVERSION
1.Pounds to kilograms
2.Kilograms to pounds
Please select the type of conversion you would like to make:2
Please enter the kilograms:50
0.0 pounds is 110.2 kilograms.0.0kilograms is 110.2 pounds. BUILD SUCCESSFUL (total time: 3 seconds)

Re: Using methods improperly

Pretend you are the computer and execute each line of code. Look carefully at the printResults method. Surely you can see why it is printing out 2 messages. Another thing to think very carefully about is what is the dWeight variable for.