OneCompiler

Create class Project (id, name, location). Define parameterized constructor. Keep a count of each object created and display the details of each project.

305

class Project(id:Int,name:String,location:String)
{
var i:Int = 0;

    def display()
    {
       println(id+" "+name+" "+" "+location)
    }
}
object Demo5 {
   
    def main(args: Array[String])
    {
	print("How Many Object = ")
	var n = scala.io.readInt
       
	var arr = Array[Project]=new Array[Project](n)
       
	for(i<-1 to n)
	{
	    print("Enter id = ")
	    var id = scala.io.readInt
	   
	    print("Enter name = ")
	    var name = scala. io. StdIn. readLine()
	   
	    print("Enter Location = ")
	    var location = scala. io. StdIn. readLine()
	   
	    arr(i) = new Project(id,name,location)
	}
       
	print("Number Of Object Created = "+n);
    }
}