Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Very Newbie Q - Static Methods (http://www.velocityreviews.com/forums/t124186-very-newbie-q-static-methods.html)

Wendy 07-08-2003 10:52 PM

Very Newbie Q - Static Methods
 
Hi,

I've been asked to do the following;

"Write a class that contains two static methods - one to convert from
Fahrenheit to centigrade, and one to perform the reverse calculation.
This class needs no input/output routines or interaction with the
user."

Well, I know this is simple enough, but I'm confused, maybe because it
is too simple! But what the hell is this going to look like with no
I/O? A little bit of help wouldn't go amiss. Maybe one day I'll be
able to understand all this stuff. One day!

Thanks very much in advance people!

Wendy

(If replying via e-mail, remove SpaM from my address... it appears
TWICE!)

Marc Rochkind 07-08-2003 11:21 PM

Re: Very Newbie Q - Static Methods
 
On Tue, 08 Jul 2003 23:52:49 +0100, Wendy
<wespamndy@morgan19spam49.fsnet.co.uk> wrote:

> Hi,
>
> I've been asked to do the following;
>
> "Write a class that contains two static methods - one to convert from
> Fahrenheit to centigrade, and one to perform the reverse calculation.
> This class needs no input/output routines or interaction with the
> user."
>
> Well, I know this is simple enough, but I'm confused, maybe because it
> is too simple! But what the hell is this going to look like with no
> I/O? A little bit of help wouldn't go amiss. Maybe one day I'll be
> able to understand all this stuff. One day!
>
> Thanks very much in advance people!
>
> Wendy
>
> (If replying via e-mail, remove SpaM from my address... it appears
> TWICE!)
>


Well, the methods indeed need do no I/O. they can use their argument(s) and
return value to pass data back and forth to their callers.

You'll probably want a little test program (main method) to test the calss,
which will probably do some O, although it needs no I.

--Marc

VisionSet 07-08-2003 11:33 PM

Re: Very Newbie Q - Static Methods
 
"Wendy" <wespamndy@morgan19spam49.fsnet.co.uk> wrote in message
news:kpimgvsra562mo2o66gt5pmr6v05vpk1hm@4ax.com...
> Hi,
>
> I've been asked to do the following [.....]
>


Grrrrrr! Don't multipost, I wouldn't have bothered answering this on
java.help if I'd known it had already been answered here!

--
Mike W



Wendy 07-09-2003 08:39 AM

Re: Very Newbie Q - Static Methods
 
Thanks for your help everyone...

Sorry about multiposting! Apologies all round.

And yes, my prof doesn't speak much english... (what is spoken I can't
make out anyway because of the extreme German accent!) Again, thanks
for help!

Chris 07-09-2003 09:03 AM

Re: Very Newbie Q - Static Methods
 
What you're being asked to do is write a 'utility class' that contains
helpful methods, rather than a class that defines a type of object and
associated operations.

Of course there's no reason why you can't write a test harness in this
or another class - you might get bonus marks for that!

i.e.

class Converter
{
public static double fahToCent( double f ) ...
// converts fahreneit to centigrade
// similar for t'other way about

// (very trivial) test harness
// doesn't necessarily have to be in this class of course
public static void main( ... )
{
System.out.println( fahToCent( 45.67 ) );
}
}

- sarge

VX 07-17-2003 08:18 PM

Re: Very Newbie Q - Static Methods
 
ok, the confusing part is not to use IO. actually, you are asked to write
only* 2 methods so this shouldnt be a problem....
Here is the template....(I dont remember the converting formulas.. :-))

public class Temperature{

public static int celsToF(int c){
int tempinf=...... //conversion formula
return tempinf;
}

public static int fahToCels(int f){
int tempinf=.........//conversion formula
return tempinf;
}

}//end of cls

PS: This code is untested....

"Wendy" <wespamndy@morgan19spam49.fsnet.co.uk> wrote in message
news:kpimgvsra562mo2o66gt5pmr6v05vpk1hm@4ax.com...
> Hi,
>
> I've been asked to do the following;
>
> "Write a class that contains two static methods - one to convert from
> Fahrenheit to centigrade, and one to perform the reverse calculation.
> This class needs no input/output routines or interaction with the
> user."
>
> Well, I know this is simple enough, but I'm confused, maybe because it
> is too simple! But what the hell is this going to look like with no
> I/O? A little bit of help wouldn't go amiss. Maybe one day I'll be
> able to understand all this stuff. One day!
>
> Thanks very much in advance people!
>
> Wendy
>
> (If replying via e-mail, remove SpaM from my address... it appears
> TWICE!)




code learner 12-24-2010 04:05 PM

public class TemperatureConverter {
public static int c2f(int c){
return c*(9/5)+32;
}
public static int f2c(int f){
return (f-32)*(5/9);
}
}


All times are GMT. The time now is 08:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.