scala/ScalaBook/chapter-03/traitsII.scala

class Person(val name: String, var surname: String,
             val fname: String, var age: Int) extends Ordered[Person] {
  def compare(that: Person) = {
    if ( surname < that.surname ) -1
    else if ( surname > that.surname ) 1
    else if ( name < that.name ) -1
    else if ( name > that.name ) 1
    else if ( fname < that.fname ) -1
    else if ( fname > that.fname ) 1
    else 0
  }
  
  override def equals (that: Any) =
    that match {
      case that: Person => compare(that) == 0
      case      _       => false
    }     
} 

var john_smith1 = new Person("John", "Smith", "Jack", 18)
var john_smith2 = new Person("John", "Smith", "Steve", 19)

if (john_smith1 < john_smith2) 
  println("<")
else 
  println(">")