Answer to Question #279170 in HTML/JavaScript Web Application for Manish Gupta

Question #279170

given list of students records.Write a program with signature as below:

Method Name: getStudentsWithMarksmoreThan()

Input : Marks - integer

output: List of students having marks more than input.


1
Expert's answer
2021-12-13T16:57:31-0500
import ​org.junit.Test;

import ​java.util.ArrayList;

import ​static org.junit.Assert.assertTrue;

public ​class Main {
   ​public static class Student
   ​{
       ​private String name;
       ​private double mark;

       ​public String getName() {
           ​return name;
       ​}
       ​public void setName(String name) {
           ​this.name = name;
       ​}
       ​public double getMark() {
           ​return mark;
       ​}
       ​public void setMark(double mark) {
           ​this.mark = mark;
       ​}
       ​@Override
       ​public String toString() {
           ​return name + ", " + mark;
       ​}
   ​}
   ​public static ArrayList<Student> getStudentsWithMarksMoreThan(ArrayList<Student> students, double mark)
   ​{
       ​ArrayList<Student> filteredStudents = new ArrayList<>();
       ​for(Student student: students)
       ​{
           ​if(student.getMark()>mark)
               ​filteredStudents.add(student);
       ​}
       ​return filteredStudents;
   ​}
   ​@Test
   ​public static void positiveTestCase()
   ​{
       ​ArrayList<Student> students = new ArrayList<>();
       ​for(int i = 0; i < 10; i++)
       ​{
           ​Student student = new Student();
           ​student.setName("Student "+ (i + 1));
           ​student.setMark(10*(i+1));

           ​students.add(student);
       ​}
       ​ArrayList<Student> filteredStudents = getStudentsWithMarksMoreThan(students, 10);
       ​assertTrue(filteredStudents.size() == 9);
       ​System.out.println("Test case is positive");
   ​}
   ​@Test
   ​public static void negativeTestCase()
   ​{
       ​ArrayList<Student> students = new ArrayList<>();
       ​for(int i = 0; i < 10; i++)
       ​{
           ​Student student = new Student();
           ​student.setName("Student "+ (i + 1));
           ​student.setMark(10*(i+1));

           ​students.add(student);
       ​}
       ​ArrayList<Student> filteredStudents = getStudentsWithMarksMoreThan(students, 50);
       ​assertTrue(filteredStudents.size() == 4);
   ​}
   ​public static void main(String[] args)
   ​{
       ​positiveTestCase();
       ​negativeTestCase();
   }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS