The point is that he's practicing programming and (supposedly) learning new things.
I might say that he's not. He's still doing typical Joe things. For instance:
if ((args.length == 0) || (args.length == 1))
How about:
if (args.length < 2)
so that we only need one runtime check if args.length == 1?
Then he's got this:
System.out.println(args[1] + " F = " + fToC(Double.parseDouble(args[1])) + " C.");
...which is not the most readable thing ever. Not exactly the most beneficial for him learning or someone else learning.
Then he has inconsistent accessibility which is shown in his JavaDoc:
public static double fToC(double temp)
private static double cToF(double temp)
An external user trying to convert Celsius to Fahrenheit will get a compile-time error because cToF is private.
Finally, his algorithms are just wrong:
/**
Converts a temperature from fahrenheit to celsius
@param temp Temperature to convert (fahrenheit)
@return Converted temperature (celsius)
*/
public static double fToC(double temp)
{
return 100.0 / 212 * (temp - 32.0);
}
/**
Converts a temperature from celsius to fahrenheit
@param temp Temperature to convert (celsius)
@return Converted temperature (fahrenheit)
*/
private static double cToF(double temp)
{
return 212.0 / 100 * temp + 32.0;
}
It's well-known that the appropriate formulae for converting between Celsius and Fahrenheit are the following:
C to F:
degreesC * 9 / 5 + 32
F to C: (
degreesF - 32) * 5 / 9
For example, when converting 10 C to Fahrenheit, Joe's program would return 53.2 F, where the correct value is actually 50 F.
Also, it is commonly known that the Fahrenheit and Celsius scales intersect at -40 degrees. Joe's algorithms, however, return the following:
-40 C to F: -52.8
-40 F to C: -33.96
Ultimately this is a completely and utterly worthless "tutorial," with the exception that it shows that you should use .equalsIgnoreCase when you're parsing command-line arguments.