OneCompiler

Define a class Employee (id, name, salary). Define methods accept() and display().//Display details of employee having maximum salary. using scala

208

//Q2. Define a class Employee (id, name, salary). Define methods accept() and display().//Display details of employee having maximum salary.


	class Empoley(id:Int, name:String)
	{  
	    var salary:Int = 0  //default value
	    def showDetails()
	    {  
		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])
	    {
		var emp:Array[Empoley]=new Array[Empoley](4)
		emp(0)=new Empoley(101,"Rama",201241)
		emp(1)=new Empoley(10,"Ram",601341)
		emp(2)=new Empoley(103,"Ramay",801234)
		emp(3)=new Empoley(104,"Ramo",1001234)
		
		
		var salary:Empoley=new Empoley(0,"",0) // a temporary object
	salary = emp(0) //assigning first record/object to max
		var maxsalary=emp(0).salary // a temporary maxmarks variable to contain max value
		for( i <-0 to 3)
		  {
		    
		    if(emp(i).salary>maxsalary)
		    {
		      maxsalary=emp(i).salary
		      salary=emp(i)
		    }
		    
		  }
		  println("student details with maximum marks is")
		  println(salary.showDetails())
	      
	    }  
	}