Program to search objects from array of objects using the filter() method.
Problem Description: In this program, we will create an array of objects and then search for objects with marks in a certain range using the filter() method.
Class Used in the program:
- Class : student
- Method : getStudentInfo() : gets input of the student information from the user.
- Method : putStudentInfo() : print in student information to the screen.
- Method : searchMarks() : returns boolean value if the marks are in the given range.
Algorithm:
- Step 1: Taking input from the user for id, name, marks of the student.
- Step 2: We will return the details of all students who passed the exam with 1st division i.e. that marks more that 60. For this we will use the inbuilt filter() method and pass the searchMarks() method with range from 60 to 100. And this give us an array of objects of all students that satisfy the condition.
- Step 3: Print the information of all students passed with 1st division.
Program to search objects from an array of objects using filter method
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer