Packages

c

o1.election

District

class District extends AnyRef

The class District represents electoral districts (Finnish: vaalipiiri). Each district has a certain number of seats for which a (larger) number of candidates compete in an election. Each district has its own candidates.

A district object is immutable.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. District
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new District(name: String, seats: Int, candidates: Vector[Candidate])

    name

    the name of the electoral district

    seats

    the number of seats (elected positions) available

    candidates

    the candidates vying for the seats in the district; there is always at least one candidate per district

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. val candidates: Vector[Candidate]
  6. def candidatesByParty: Map[String, Vector[Candidate]]

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    Returns a mapping from parties to their candidates. That is, returns a Map whose keys are the names of all the parties that have candidates in this district. For each key, the value is a vector containing the candidates from that party in arbitrary order. (The order is arbitrary in the sense that the method is free to choose whichever order; this does not imply randomization.)

    See also

    rankingsWithinParties

  7. def candidatesFrom(party: String): Vector[Candidate]

    Returns all the candidates in this district that belong to the party named by the parameter.

  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  9. def distributionFigures: Map[Candidate, Double]

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    Returns a mapping of candidates to their distribution figures (Finnish: vertailuluku). That is, returns a Map whose keys are all the candidates in this district and whose values are the distribution figures of those candidates.

    The distribution figure of a candidate is obtained as follows. Take the position (rank) of the candidate in the ranking list within his or her own party (as defined by rankingsWithinParties). For instance, the most-voted-for candidate within a party has a rank of 1, the second-most-voted-for has a rank of two, and so on. Divide the total number of votes received by the candidate's party by the candidate's rank, and you have the candidate's distribution figure.

    If multiple candidates from a single party received the same number of votes, the arbitrary order chosen by rankingsWithinParties is used here, despite the fact that this is likely to be a undesirable feature in a real-world system.

    See also

    votesByParty

    rankingsWithinParties

    electedCandidates

  10. def electedCandidates: Vector[Candidate]

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    Returns all the candidates who will be elected on the basis of the vote. The seats available are given to the candidates with the highest distribution figures.

    If multiple candidates happen to have the same distribution figure, an arbitrary order is used, despite the fact that this is likely to be a undesirable feature in a real-world system. (The order is arbitrary in the sense that the method is free to choose whichever order; this does not imply randomization.)

    returns

    the elected candidates in descending order by distribution figure

    See also

    distributionFigures

  11. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  12. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  13. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. val name: String
  17. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  19. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  20. def printCandidates(): Unit

    Prints (to the console) a description of each candidate in this district, each on a line of its own.

    Prints (to the console) a description of each candidate in this district, each on a line of its own. A candidate's description is obtained by calling its toString method.

    NOTE TO STUDENTS: It's not usually a good idea to create "print some of your data" methods ("return some information" methods are better), but we're still making one as an exercise here. More about this in later chapters.

  21. def rankingOfParties: Vector[String]

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    Returns a vector containing the names of all the parties that have candidates in this district, ordered by the total number of votes received by each party. Descending order is used, so the party with the most votes comes first.

    If multiple parties received the same number of votes, this method orders them in an arbitrary way. (The order is arbitrary in the sense that the method is free to choose whichever order; this does not imply randomization.)

  22. def rankingsWithinParties: Map[String, Vector[Candidate]]

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    Returns a mapping from parties to ranking lists of those parties' candidates. That is, returns a Map whose keys are the names of all the parties that have candidates in this district. For each key, the value is a vector containing the candidates from that party in order by the number of votes they received, starting with the highest.

    If multiple candidates from a single party received the same number of votes, this method returns those candidates in an arbitrary order. (Arbitrary in the sense that those candidates may be in whichever order, not in the sense of randomizing the order.)

  23. val seats: Int
  24. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  25. def toString: String

    Returns a textual description of the district.

    Returns a textual description of the district. The description is of the form Name: X candidates, Y seats, where Name is the name of the district, and X and Y the numbers of candidates and seats, respectively. For instance, might return the string Helsinki: 1064 candidates, 85 seats

    Definition Classes
    District → AnyRef → Any
  26. def topCandidate: Candidate

    Returns the top candidate (Finnish: ääniharava) of the district.

    Returns the top candidate (Finnish: ääniharava) of the district. That is, returns the candidate with the highest number of votes. If multiple candidates have the same number of votes, this method chooses one of them arbitrarily. It is assumed that every district always has at least one candidate.

  27. def topCandidatesByParty: Map[String, Candidate]

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    Returns a mapping from parties to their top candidates. That is, returns a Map whose keys are the names of all the parties that have candidates in this district. For each key, the value is the candidate from that party with the most votes.

    If multiple candidates from a single party received the same number of votes, this method chooses one of them arbitrarily.

  28. def totalVotes(party: String): Int

    Returns the total number of votes received by members of the party named by the parameter.

  29. def totalVotes: Int

    Returns the total number of votes received by all the candidates, that is, the total number of votes cast in this district.

  30. def votesByParty: Map[String, Int]

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    NOTE TO STUDENTS: THIS METHOD IS ONLY INTENDED FOR IMPLEMENTATION IN CHAPTER 9.2!

    Returns a mapping from parties to their vote totals. That is, returns a Map whose keys are the names of all the parties that have candidates in this district. For each key, the value is the number of votes received in total by all the members of that party in this district.

  31. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  32. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  33. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from AnyRef

Inherited from Any

Ungrouped