Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the error "not found: type Score"?

main.scala:

import java.time.LocalDate
  object OptionAnswer {
  def main(args: Array[String]): Unit = {
    case class Score(
      name:    String,    // 学生の名前
      english: Int,       // 英語の点数
      math:    Int,       // 数学の点数
      science: Int,       // 理科の点数
      date:    LocalDate  // 受験日
    )
    val scoreOfAlice   = Score(name = "Alice",   english = 77,  math = 74, science = 26, date = LocalDate.of(2020, 1, 30))
    val scoreOfBob     = Score(name = "Bob",     english = 100, math = 74, science = 14, date = LocalDate.of(2020, 1, 26))
    val scoreOfCharlie = Score(name = "Charlie", english = 100, math = 74, science = 99, date = LocalDate.of(2020, 1, 26))
    val scoreOfDave    = Score(name = "Dave",    english = 50,  math = 81, science = 88, date = LocalDate.of(2020, 1, 30))
    val scoreSeq: Seq[Score] = List(scoreOfAlice,scoreOfBob,scoreOfCharlie,scoreOfDave)
    println(getTotalRanking(scoreSeq))
  }
  def getTotalRanking(scoreSeq: Seq[Score]): Seq[String] = {
    val p: Seq[Score] = scoreSeq.sortBy(score => score.english+score.math+score.science)(Ordering.Int.reverse)
    p.map(score=>score.english+score.math+score.science)
  }
  }

error:

not found: type Score
[error]   def getTotalRanking(scoreSeq: Seq[Score]): Seq[String] = {
[error]          
not found: type Score
[error]     val p: Seq[Score] = scoreSeq.sortBy(score => score.english+score.math+score.science)(Ordering.Int.reverse)
[error]                ^
[error] two errors found

How do I resolve this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Class Score is nested into the method. It’s not seen outside. Move it outside.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading