Very Newbie Q - Static Methods

W

Wendy

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!)
 
M

Marc Rochkind

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
 
V

VisionSet

Wendy said:
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!
 
W

Wendy

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!
 
C

Chris

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
 
V

VX

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....
 
Joined
Dec 24, 2010
Messages
19
Reaction score
0
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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top