Class City

  • All Implemented Interfaces:
    java.lang.Comparable<City>

    public class City
    extends java.lang.Object
    implements java.lang.Comparable<City>
    Class containing all information regarding cities (such as location, direct connections, etc.) with some functionalities (such as distance between to cities) This class implements the Comparable interface so cities can get sorted by their x-coordinate
    Author:
    Klara Schöbel
    • Constructor Summary

      Constructors 
      Constructor Description
      City​(int x, int y, java.lang.String name, int maxConnections)
      Constructs a city at the given coordinates, with a name and maximum capacity for connections
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addDirectConnection​(City cityB)
      adds another city to vector containing all direct connections (directConnections)
      boolean atMaxCapacity()
      test if the max capacity has been reached
      int compareTo​(City other)
      Method needed for the implementation of the comparable interface.
      boolean equals​(java.lang.Object o)
      Override for equals method to fit the logic behind cities,
      cities are equal if they have the same name and coordinates
      int getActualConnections()
      getter for actualConnections
      int getDistanceBetweenCities​(City cityB)
      calculates the distance between this city and a given city
      int getMaxConnections()
      getter for maxConnections
      java.lang.String getName()
      getter for name
      int getX()
      getter for xPos
      int getY()
      getter for yPos
      boolean hasDirectConnections​(City cityB)
      tests for direct connection between this city and another given city
      void setActualConnections()
      setter for actual Connections (since only one connection can be made at a time it only increments)
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • City

        public City​(int x,
                    int y,
                    java.lang.String name,
                    int maxConnections)
        Constructs a city at the given coordinates, with a name and maximum capacity for connections
        Parameters:
        x - x Coordinate (see also getX())
        y - y Coordinate (see also getY())
        name - Name of the city (see also getName())
        maxConnections - number of possible connections (see also getMaxConnections())
    • Method Detail

      • addDirectConnection

        public void addDirectConnection​(City cityB)
        adds another city to vector containing all direct connections (directConnections)
        Parameters:
        cityB - city-object this city has a direct connection to
      • hasDirectConnections

        public boolean hasDirectConnections​(City cityB)
        tests for direct connection between this city and another given city
        Parameters:
        cityB - a city-object to be tested
        Returns:
        if there is a direct connection to cityB
      • getDistanceBetweenCities

        public int getDistanceBetweenCities​(City cityB)
        calculates the distance between this city and a given city
        Parameters:
        cityB - a city-object
        Returns:
        distance to the given city object
      • getX

        public int getX()
        getter for xPos
        Returns:
        x coordinate of this city
      • getY

        public int getY()
        getter for yPos
        Returns:
        y coordinate of this city
      • getName

        public java.lang.String getName()
        getter for name
        Returns:
        name of this city
      • getMaxConnections

        public int getMaxConnections()
        getter for maxConnections
        Returns:
        maximal number of connections possible in this city
      • getActualConnections

        public int getActualConnections()
        getter for actualConnections
        Returns:
        number of actual connections
      • setActualConnections

        public void setActualConnections()
        setter for actual Connections (since only one connection can be made at a time it only increments)
      • atMaxCapacity

        public boolean atMaxCapacity()
        test if the max capacity has been reached
        Returns:
        if there are less actual connections than possible connections
      • compareTo

        public int compareTo​(City other)
        Method needed for the implementation of the comparable interface. Used to sort the cities in the board class by their x-coordinate.
        Specified by:
        compareTo in interface java.lang.Comparable<City>
      • equals

        public boolean equals​(java.lang.Object o)
        Override for equals method to fit the logic behind cities,
        cities are equal if they have the same name and coordinates
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - object (city) to be compared with
        Returns:
        if the two objects are equal