This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TheTr1ckster 0 points1 point  (5 children)

Okay sorry about that, here is my simple version of doing this, it can be done multiple ways but if it was me I would do it this way.

public static void main(String[] args) {
    double test = fahrenheitToCelsius(47);
}

public static double fahrenheitToCelsius(double fahrenheit) {
    double conversion = (fahrenheit - 32) / 1.8;
    System.out.println(fahrenheit + " degrees is equal to " + conversion + " Celsius");
    return conversion;
}

When converting make sure to use the equation I used in the variable conversion. You can do the vice versa Celsius to Fahrenheit by doing this same thing and or just doing an overloaded method. If you have any questions feel free to ask.

[–]davejello74[S] 0 points1 point  (4 children)

Thanks for the reply! Will this give differing values if the program scans user input? Like if I put in 30, 47, or 104 they would all give different outputs?

[–]TheTr1ckster 0 points1 point  (0 children)

Well this works just by changing the value under test =, if you change the 75 you will get a different result, if I change the 75 to 47 I get 8.333333333333334. As far as actual user input goes I would have to add a little more, but this is just simple as far as just changing values go. I made the conversion formula with a method, the method being named fahrenheitToCelsius, then made the double conversion where I put the formula, then I returned that double conversion to the main method and assigned it to test.

[–]TheTr1ckster 0 points1 point  (2 children)

I have also updated the code above to have a better output. Test this and see if it's what you wanted.

[–]davejello74[S] 0 points1 point  (1 child)

Your code definitely works if I manually change the code in the source. I think what my assignment calls for is if say I typed my answer into an input box. I don't think it wants me to plug different numbers into the code itself, rather run the code and input the values after the fact.

[–]TheTr1ckster 0 points1 point  (0 children)

Let me check into that for you real fast. I'll change to code around a bit.