Results 1 to 2 of 2

Thread: Celsius to Faherneit convertor starting at 90 degrees

  1. #1
    Join Date
    Feb 2009
    Thanked 0 Times in 0 Posts

    Default Celsius to Faherneit convertor starting at 90 degrees

    Hi I am having problems with a college assignment

    Its a celsius to Fahrenheit converter I have the first part working however the

    second part of the project involves coding the converter to convert from 90 degrees celsius to 95 degrees celsius.

    I figure the best way is through an if or else statement but I not sure how to work this into the code I have.

    the third part of the project involves using decimal format when I try to run the decimal format the project fails.

    The code for 90 degrees upwards is as follows

    I guess I use an if or else statement

    if 90

    else 90<

    if((int)((degree - 32) * 5)/9 == 90) {
    System.out.println("194 degrees Fahrenheit");
        } else if ((int)((194 - 32) * 5)/9 == <90 ) {
            System.out.println(" degrees Fahrenheit" );
    but not sure how to work this into the code

    the code for the decimal format I have is

    import java.text.Decimalformat;
    DecimalFormat oneDigit = new
    DecimalFormat ("0.0");
    System.out.println("90"+ oneDigit.Format (f));

    The following is for the code for the converter working as normal.

    package converter;
    import javax.swing.JOptionPane;
    public class Converter {
        public static void main(String[] args) {
     String degreestring = JOptionPane.showInputDialog("Enter a temperature in degrees Celsius:");
     int degree;
    degree = Integer.parseInt( degreestring );
    int fahrenheit;
    fahrenheit = (int) ((9.0 / 5.0) * degree + 32.0);
    JOptionPane.showMessageDialog(null, degree + " degrees Celsius = " + fahrenheit + " degress Fahrenheit");
    Any help would be greatly appreciated. thanks
    Last edited by tomwaits4noman; 10-18-2009 at 03:53 PM. Reason: adding if or else statement

  2. #2
    Join Date
    Mar 2006
    Illinois, USA
    Thanked 690 Times in 678 Posts


    I don't get why there is any difference in 90 and 95 degrees: both are numbers, and you can use the same equation to convert both. Just use a variable, do the math, and that's it.
    Generally we encourage those doing homework assignments to figure it out themselves, because otherwise you're not learning what you have to for the course, if we just do it for you. But as I said, if you just approach this as a one step thing, it should be easy-- just use a variable and go from there. The different values can be determined by what value you set the variable to before the conversion.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum


Posting Permissions

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