Results 1 to 3 of 3
  1. #1
    peliasrojo is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default New in Java: Class example

    Hi, i'm new in Java and i've a doubt with an exercise and the form of simulate it. The exercise consists in complete the class which converts farenheits to celsius.

    The code is:


    package ehu.student;

    public class ConversorTemperaturas{
    /**
    *Converts the ºC to Farenheit
    /
    public float farenheit2celsius(float t){
    }
    /**
    * Return Farenheit to Celsius
    */

    public float farenheit2celsius (float t){

    /* Here i insert my code */

    float celsius;
    celsius = (t-32)/1.8;
    return(celsius);

    }
    }

    The questions are, is the class well-made? How can i simulate it?
    I'm working with Eclipse.

    Thank you. Regards, peliasrojo

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: New in Java: Class example

    You must have studied absolutely nothing if you don't know yet how to make a main() method to run some stuff. That's the very first thing everyone learns. Try picking up any book on Java and reading the first chapter.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: New in Java: Class example

    Please wrap your code with [code] tags so that it is easier to read, e.g.,
    [code]
    // your code here
    [/code]

    It preserves formatting and provides syntax highlighting, e.g.,
    Java Code:
        // your code here
    There are a few fundamental things to learn:

    1. Create a main method

    See Lesson: A Closer Look at the "Hello World!" Application (The Java™ Tutorials > Getting Started). The main method is the starting point for a standalone Java program.

    2. Create the ConversorTemperaturas object and call the object's method

    See Objects (The Java™ Tutorials > Learning the Java Language > Classes and Objects), including the 2 subsections, Creating Objects and Using Objects. The next step here is to instantiate the ConversorTemperaturas class for the object, and then call the object's farenheit2celsius method. The instantiation and method call are done in the main method.

    Besides that, see Variables (The Java™ Tutorials > Learning the Java Language > Language Basics) for the way variables are declared. There's no need to separate them into 2 lines for the particular case below:
    Java Code:
    float celsius;
    celsius = (t-32)/1.8;
    Note that since you're using Eclipse, you should see that there's a problem with
    Java Code:
    celsius = (t-32)/1.8
    Finally, I've noticed the following is commented out:
    Java Code:
    /**
    *Converts the ºC to Farenheit
    /
    public float farenheit2celsius(float t){
    }
    This is where the celsius2Fahrenheit method should go, right?

    gimbal2 has a point that the above are very fundamental to Java. If you don't have a Java book with you, you should at least go through Trail: Learning the Java Language: Table of Contents (The Java™ Tutorials) to learn how to properly get started with Java. The more you delay learning the fundamentals, the more confusing it will become later.

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2013, 04:19 PM
  2. Replies: 8
    Last Post: 12-14-2012, 02:01 PM
  3. Replies: 6
    Last Post: 03-01-2012, 03:07 PM
  4. Replies: 3
    Last Post: 01-26-2012, 11:20 PM
  5. Replies: 14
    Last Post: 05-28-2009, 05:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •