lunduniversity / introprog

Teaching material for "Introduction to Programming using Scala" at Lund University, LTH. http://cs.lth.se/pgk/
140 stars 167 forks source link

explain in more detail how simple enums can be used in shuffle w07 #701

Closed bjornregnell closed 1 year ago

bjornregnell commented 1 year ago

Several students use advanced enums instead of simple in the last task of shuffle, but that was not the objective. Example of usage with extends that has not been lectured:

  enum Category(val englishName: String, val swedishName: String):
    case RoyalFlush    extends Category("royal flush",     "royal flush")
    case StraightFlush extends Category("straight flush",  "färgstege"  )
    case Fours         extends Category("four of a kind",  "fyrtal"     )
    case FullHouse     extends Category("full house",      "kåk"        )
    case Flush         extends Category("flush",           "färg"       )
    case Straight      extends Category("straight",        "stege"      )
    case Threes        extends Category("three of a kind", "tretal"     )
    case TwoPair       extends Category("two pairs",       "två par"    )
    case OnePair       extends Category("pair",            "par"        )
    case HighCard      extends Category("high card",       "högt kort"  )
    case None          extends Category("nothing",         "inget"      )

This shoud be a simple enum instead and the naming logic should be kept in another singelton:

enum Category:
  case RoyalFlush, StraightFlush, Fours, FullHouse, Flush, Straight, Threes, TwoPair, OnePair, HighCard, None
bjornregnell commented 1 year ago

Won't fix as this is now made optional. image