English subtitles

← Using Interfaces for Algorithm Reuse Average Area - Intro to Java Programming

Get Embed Code
6 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. You've seen some interesting interfaces with drawable and likeable, but let me
  2. give you another very common reason why people like to use interfaces. And that
  3. is to be able to reuse an algorithm. Consider a common algorithm to compute an
  4. average. Here I have an array of countries, each of which has a name and an
  5. area. And I want to know, what is the average area of all of these countries.
  6. Now of course, I could write a loop to compute that, but lets say I want to a
  7. method that does this for any set of countries. So, I'd like you to complete
  8. this method that takes an array of countries. For each of them, find out what
  9. the area is simply by calling the Get Area method. Add up all those areas, and
  10. then return the average.