Class City


  • public class City
    extends Object
    A city, represented by a name and two-dimensional coordinates.
    • Constructor Detail

      • City

        public City​(String name,
                    double x,
                    double y)
        Parameters:
        name - Name.
        x - Cartesian x-coordinate.
        y - Cartesian y-coordinate.
    • Method Detail

      • getCoordinates

        public double[] getCoordinates()
        Returns:
        the (x, y) coordinates.
      • distance

        public double distance​(double x,
                               double y)
        Computes the distance between this city and the given point.
        Parameters:
        x - x-coordinate.
        y - y-coordinate.
        Returns:
        the distance between (x, y) and this city.
      • closest

        public static City closest​(double x,
                                   double y,
                                   Set<City> cities)
        Parameters:
        x - x-coordinate.
        y - y-coordinate.
        cities - City list.
        Returns:
        the city whose coordinates are closest to (x, y).
      • barycentre

        public static double[] barycentre​(Set<City> cities)
        Computes the barycentre of all city locations.
        Parameters:
        cities - City list.
        Returns:
        the barycentre.
      • largestDistance

        public static double largestDistance​(double x,
                                             double y,
                                             Set<City> cities)
        Computes the largest distance between the point at coordinates (x, y) and any of the cities.
        Parameters:
        x - x-coordinate.
        y - y-coordinate.
        cities - City list.
        Returns:
        the largest distance.
      • unique

        public static Set<Cityunique​(City[] cities)
        Parameters:
        cities - List of cities.
        Returns:
        a list with no duplicate city.