Created
May 9, 2018 09:29
-
-
Save deepankar14693/591dd9839e9904f7686c5ff7351155a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable.ListBuffer | |
class Students { | |
val students = ListBuffer(Student(1, "Ayush"), Student(2, "deepankar")) | |
def fetchStudents: ListBuffer[Student] = students | |
def addStudent(student: Student): ListBuffer[Student] = { | |
student +: students | |
} | |
def updateStudent(student: Student): ListBuffer[Student] = { | |
val oldRecord = students.filter(_.rollNum == student.rollNum) | |
students --= oldRecord | |
student +: students | |
} | |
def deleteStudent(rollNum: Int): ListBuffer[Student] = { | |
val deleteRecord = students.filter(_.rollNum == rollNum) | |
students --= deleteRecord | |
} | |
case class Student(rollNum: Int, name: String) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment