Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

isral bustami
PLUS
isral bustami
Courses Plus Student 5,932 Points

stuck making temperature conversion method

i am trying to convert temperature it work but the math formula didn't work

i use this method

public int getFormattedTemperature() {
        int tempInFarenheit = (int) Math.round(mTemperature);
        int tempInCelcius = 5/9*(tempInFarenheit - 32);
        return Math.round(tempInCelcius);
    }

then i make onClickListener

mTempMeasure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mTempMeasure.getText() == "F") {
                   mTemperatureLabel.setText(mCurrentWeather.getFormattedTemperature() + "");
                   mTempMeasure.setText("C");
               }else {
                    mTemperatureLabel.setText(mCurrentWeather.getTemperature() + "");
                    mTempMeasure.setText("F");
                }

            }
        });

it display "0" when i click to convert to celcius

could someone give me a hint..?

1 Answer

Quincy Leito
Quincy Leito
20,503 Points

Just call the method getTemperature() in the getFormattedTemperature() method. Like this;

public int getFormattedTemperature() {
     return ((getTemperature() - 32)*5)/9;
}

Hope it helps :D

isral bustami
isral bustami
Courses Plus Student 5,932 Points

so that is how we do it.... i get it now... thank you much