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. Advertisements

  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. Advertisements

  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
    Likes Received:
    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);
    }
    }
     
    code learner, Dec 24, 2010
    #7
    1. Advertisements

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. Neo
    Replies:
    1
    Views:
    721
    Scott Allen
    Jan 7, 2005
  2. 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:
    723
    Raymond Hettinger
    Jul 27, 2003
  3. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    2,053
    Merrill & Michele
    Oct 19, 2004
  4. Abhishek Jha

    very very very long integer

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

    Very very very basic question

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

    Help running a very very very simple code

    olivier.melcher, May 12, 2008, in forum: Java
    Replies:
    8
    Views:
    2,782
  7. Hasan Kachal

    Very very newbie ?

    Hasan Kachal, Jul 20, 2004, in forum: ASP General
    Replies:
    4
    Views:
    198
    Hasan Kachal
    Jul 21, 2004
  8. Kenneth McDonald
    Replies:
    5
    Views:
    644
    Kenneth McDonald
    Sep 26, 2008
Loading...