OneCompiler

Employee

215

class Employee(id: Int, name: String) {
var salary: Int = 0 //default value

def showDetails():Unit = {
println(id + " " + name + " " + salary)
}

def this(id: Int, name: String, salary: Int) {
this(id, name) // Calling primary constructor (see parameters in class decalration)
this.salary = salary
}
}

object MainObject {
def main(args: Array[String]):Unit = {
var employee: Array[Employee] = new ArrayEmployee
employee(0) = new Employee(101, "Ram", 200)
employee(1) = new Employee(10, "Rama", 60)
employee(2) = new Employee(103, "Ramay", 80)
employee(3) = new Employee(104, "Ram", 100)

var max: Employee = new Employee(0, "", 0) // a temporary object
max = employee(0) //assigning first record/object to max
var maxsalary = employee(0).salary // a temporary maxmarks variable to contain max value
for (i <- 0 to 3) {

  if (employee(i).salary > maxsalary) {
    maxsalary = employee(i).salary
    max = employee(i)
  }

}
println("Employee details with maximum salary is")
println(max.showDetails())

}
}