Home > front end >  What is the error "not found: type Score"?
What is the error "not found: type Score"?

Time:10-28

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?

CodePudding user response:

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

  • Related