Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package o1.election
- class District(val name: String,val seats: Int,val candidates: Vector[Candidate]) {
- def candidatesFrom (party2: String): Vector[Candidate] = {
- var wek = Vector[Candidate]()
- //for( index <- 0 to candidates.length-1 )
- //{
- // if( candidates(index).party == party2 ) wek = wek :+ candidates(index)
- //}
- wek = candidates.filter( _.party==party2)
- wek
- }
- override def toString: String = {
- var nap = "juhu"
- nap= name + ": " + candidates.length + " " + "candidates " + seats + " seats"
- nap
- }
- def topCandidate: Candidate = {
- var najlepszy = candidates(0)
- var najglo = candidates(0).votes
- for( index <- 0 to candidates.length -1)
- {
- if(najglo< candidates(index).votes)
- {
- najlepszy = candidates(index)
- najglo = candidates(index).votes
- }
- }
- najlepszy
- }
- def printCandidates(): Unit = {
- // for (index <- 0 to candidates.length-1)
- // println(candidates(index).toString)
- candidates.foreach( strin => println( strin.toString ) )
- }
- def totalVotes(party: String) = {
- var ile=0
- // for( i <- 0 to candidates.length-1)
- // {
- // if(candidates(i).party == party) ile+=candidates(i).votes
- // }
- //ile
- var pom2 = candidates.filter(_.party==party)
- if(pom2.size>0)pom2.foldLeft( 0 )( (wyn , next) => wyn + next.votes)
- else 0
- }
- def totalVotes = {
- var ile=0
- for( i <- 0 to candidates.length-1)
- {
- ile+=candidates(i).votes
- }
- ile
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement