Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

ScalaAssignment

//Question 1
implicit def toInt(value: String): Int = value.toInt
implicit def toString(student: Student): String = student.name
case class Student(id:Int, name:String)

val studentName:String = Student("10","John Dole")





//Question 2
implicit def toList(marks: Marks): List[Int] = marks.marks
case class Marks(course:String, marks:List[Int])

def totalMarks(marks: List[Int]):Int = marks.sum

val marks = List(80,50,100,30)

totalMarks(Marks("FunctionalProgramming",marks))

//Question 3
case class Course(subjects:List[String])

def getNumberofSubjects(course:Course):Int = course.subject.size

getNumberofSubjects


//Question 4
implicit class greetTheWorld(helloWorld: HelloWorld){
    
    def greetTheWorld = helloworld.greeting
}
class HelloWorld{
    def greeting ="Greeting from hello World"
    
    val getGreeting = new HelloWord().greetTheWorld
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.