Very Newbie Q - Static Methods

Discussion in 'Java' started by Wendy, Jul 8, 2003.

  1. Wendy

    Wendy Guest

    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!)
     
    Wendy, Jul 8, 2003
    #1
    1. Advertising

  2. On Tue, 08 Jul 2003 23:52:49 +0100, Wendy
    <> 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
     
    Marc Rochkind, Jul 9, 2003
    #2
    1. Advertising

  3. Wendy

    VisionSet Guest

    "Wendy" <> wrote in message
    news:...
    > 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
     
    VisionSet, Jul 9, 2003
    #3
  4. Wendy

    Wendy Guest

    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!
     
    Wendy, Jul 9, 2003
    #4
  5. Wendy

    Chris Guest

    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
     
    Chris, Jul 9, 2003
    #5
  6. Wendy

    VX Guest

    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" <> wrote in message
    news:...
    > 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!)
     
    VX, Jul 17, 2003
    #6
  7. Wendy

    code learner

    Joined:
    Dec 24, 2010
    Messages:
    19
    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);
    }
    }
     
    code learner, Dec 24, 2010
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    483
    Raymond Hettinger
    Jul 27, 2003
  2. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,632
    Merrill & Michele
    Oct 19, 2004
  3. Abhishek Jha

    very very very long integer

    Abhishek Jha, Oct 16, 2004, in forum: C Programming
    Replies:
    4
    Views:
    427
    jacob navia
    Oct 17, 2004
  4. Peter

    Very very very basic question

    Peter, Feb 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    519
    Dave Thompson
    Feb 14, 2005
  5. olivier.melcher

    Help running a very very very simple code

    olivier.melcher, May 12, 2008, in forum: Java
    Replies:
    8
    Views:
    2,305
Loading...

Share This Page