Results 1 to 3 of 3
  1. #1
    Danieldcc is offline Member
    Join Date
    Sep 2010
    Posts
    83
    Rep Power
    0

    Default Celsius to Fahrenheit

    so my first assignment is to convert celsius to fahrenheit and I think that I got eveything right, except my last taks is to


    Write a main method for the previous class Temperature that creates an object of that type and then calls its methods, outputting the result on the console.

    I did that but the input is already set to 100 and just outputs the values in the console window. Is there a really quick way just to ask the user for an input in fahrenheit and output in console window in both fahrenheit and celsius and vice versa???

    public class Temperature
    //Converts between Celsius and Fahrenheit and outputs the conversion
    {
    private double celsius;
    private double fahrenheit;
    //converts from celsius to fahrenheit and stores in variables
    public void setCelsius(double temp){
    fahrenheit = 9.0/5.0*temp + 32;
    celsius = temp;
    }
    //converts from fahrenheit to celsius and stores in variable
    public void setFahrenheit(double temp){
    celsius = (temp-32) * 5.0/9.0;
    fahrenheit = temp;
    }
    //prints the temperature in celsius in the console
    public void outputCelsius(){
    System.out.println("The temperature is " + celsius + "C");
    }
    //prints the temperature in fahrenheit in the console
    public void outputFahrenheit(){
    System.out.println("The temperature is " + fahrenheit + "F");
    }
    //Creating an object that will output the temperature on the cosnole window
    public static void main(String[] args) {
    Temperature t = new Temperature();
    t.setCelsius(100);
    t.outputFahrenheit();
    t.outputCelsius();
    }
    }

  2. #2
    jlmp is offline Member
    Join Date
    Sep 2010
    Posts
    21
    Rep Power
    0

    Default

    For input, check the the class Scanner and for output you alread have System.out to show your results on your console !

  3. #3
    Danieldcc is offline Member
    Join Date
    Sep 2010
    Posts
    83
    Rep Power
    0

    Default

    Thanks for the info. I heard about the Scanner but we didn't learn that in class so I'm assuming I don't need to do it.

Similar Threads

  1. Fahrenheit to Celcius program error
    By bosoxfan in forum New To Java
    Replies: 3
    Last Post: 02-10-2010, 03:38 AM
  2. Help with fahrenheit to celsius conversion
    By java_is_killingme in forum New To Java
    Replies: 4
    Last Post: 03-07-2009, 11:11 AM
  3. Fahrenheit to celsius
    By lalithalydia in forum New To Java
    Replies: 3
    Last Post: 02-05-2008, 07:50 AM
  4. farenheit to celsius
    By lalithalydia in forum New To Java
    Replies: 2
    Last Post: 02-02-2008, 08:44 AM
  5. Converts from Fahrenheit to Celsius
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:52 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
  •