Fahrenheit <=> Celsius Converter

Started by Joe, April 09, 2006, 01:56:18 PM

Previous topic - Next topic

0 Members and 4 Guests are viewing this topic.

Joe

http://www.javaop.com/uploads/guest/FCConverter.tar.gz

It's more of an example of how to do this than anything. Plus it shows how to use the Java tool line to create javadocs (and cut them down to only what you need), run the java disassembler (and stick it in a file), and of course, compile. Shell script included to do that stuff.

EDIT -
Replaced assembler with disassembler (hehe, oops).
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


rabbit


Joe

Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Sidoh


Ergot

Quote from: Newby on February 26, 2006, 12:16:58 AM
Who gives a damn? I fuck sheep all the time.
Quote from: rabbit on December 11, 2005, 01:05:35 PM
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Sidoh

Quote from: Ergot on April 09, 2006, 02:43:36 PM
Just add 273 to Celcius :\

I know. : - P

I want his program to do it for me.

Joe

Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


MyndFyre

Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

Joe

QuoteAnd that reason is?
You're kidding, right? To show others how I did it, and for Sigh-dough to add his nice modification. ^_^
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Sidoh

Quote from: MyndFyrex86] link=topic=5504.msg64307#msg64307 date=1144613172]
273.15

Depends on significant digits and desired accuracy. ;)

deadly7

Is it me or does this seem like a really basic thing to make?
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
[17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

MyndFyre

Quote from: deadly7 on April 09, 2006, 06:24:18 PM
Is it me or does this seem like a really basic thing to make?
z0mG N00es!  J00 gotta get teh 1nput, m4ke 1t a num|3er, times and add teh numb3rz, n put 1t on t3h scr33nz.  c0mp|_icated!!!!!!1!1!11!1!one11!
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

Quik

Quote from: deadly7 on April 09, 2006, 06:24:18 PM
Is it me or does this seem like a really basic thing to make?

In most "learn to program" books, this is the 2nd or 3rd program it has you make. Complexity is not the point here, not even usefulness (though I can see a situation where someone might find it handy). The point is that he's practicing programming and (supposedly) learning new things.

From your comment, I take it you can make this same program in a quick 5 minutes? Thought so.
Quote[20:21:13] xar: i was just thinking about the time iago came over here and we made this huge bomb and light up the sky for 6 min
[20:21:15] xar: that was funny

MyndFyre

Quote from: Quik on April 09, 2006, 06:36:20 PM
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.
Quote from: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

deadly7

Quote from: Quik on April 09, 2006, 06:36:20 PM
Quote from: deadly7 on April 09, 2006, 06:24:18 PM
Is it me or does this seem like a really basic thing to make?

In most "learn to program" books, this is the 2nd or 3rd program it has you make. Complexity is not the point here, not even usefulness (though I can see a situation where someone might find it handy). The point is that he's practicing programming and (supposedly) learning new things.

From your comment, I take it you can make this same program in a quick 5 minutes? Thought so.
Uh.  Joe boasts about his programming knowledge, and unless he picked up a new language I doubt this is learning something new for him.

I don't program.  Programming bores me.
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
[17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine