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 Build a Weather App (2015) Hooking Up the Model to the View Plugging in the Data

Diego Marrs
Diego Marrs
8,243 Points

Question about the casting

Hello,

So we casted getTemperature() to an int, but we used Math.round to round it to the nearest number. Wouldn't doing that already make it an int value?

Also, where does the weather app get it's info? Because I compared the info of the weather app we created to another app and the info was different.

Please help!

1 Answer

Alexey Papin
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexey Papin
iOS Development Techdegree Graduate 26,950 Points
  1. If you talking about this part of code:

public int getPrecipChance() { double precipPercentage = mPrecipChance * 100; return Math.round(precipPercentage); }

Yes, we have to cast it to int because there are 2 functions Math.round: first, with float argument returns int, and second with double argument (wich one is in our code) - returns long:

https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html static long round(double a) Returns the closest long to the argument, with ties rounding up. static int round(float a) Returns the closest int to the argument, with ties rounding up.

  1. Weather app gets info from "https://forecast.io/" using that forecast API