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.
- Alphabetic
- By Inheritance
- District
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- val candidates: Vector[Candidate]
- 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
- def candidatesFrom(party: String): Vector[Candidate]
Returns all the candidates in this district that belong to the party named by the parameter.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- 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. - 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
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val name: String
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- 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.
- 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.)
- 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.)
- val seats: Int
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- 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
, whereName
is the name of the district, andX
andY
the numbers of candidates and seats, respectively. For instance, might return the stringHelsinki: 1064 candidates, 85 seats
- Definition Classes
- District → AnyRef → Any
- 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.
- 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.
- def totalVotes(party: String): Int
Returns the total number of votes received by members of the party named by the parameter.
- 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.
- 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. - final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- 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.