Scala code(Functional and Object Oriented)