|
| 1 | +package com.lwl.junit; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.List; |
| 5 | +import java.util.Map; |
| 6 | +import java.util.function.Predicate; |
| 7 | +import java.util.stream.Collectors; |
| 8 | + |
| 9 | + |
| 10 | +public class CourseDataManager { |
| 11 | + private static List<CourseData> cdArray; |
| 12 | + |
| 13 | + |
| 14 | + { |
| 15 | + CSVManager<CourseData> csvm = new CSVManager<CourseData>("src/main/resources/coursedata.csv"); |
| 16 | + cdArray = csvm.getList(); |
| 17 | + } |
| 18 | + |
| 19 | + |
| 20 | + void StudentQualBEMCABSCtest() { |
| 21 | + System.out.println("-----------------------------------------------------------------------------------------------------"); |
| 22 | + System.out.println("StudentQualBEMCABSCtest"); |
| 23 | + Predicate<CourseData> pd = (c -> (c.getDegree().equalsIgnoreCase("BE") || c.getDegree().equalsIgnoreCase("MCA") |
| 24 | + || c.getDegree().equalsIgnoreCase("BSC"))); |
| 25 | + |
| 26 | + cdArray.stream().filter(pd).forEach(System.out::println); |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | + void StudentCountBEtest() { |
| 31 | + System.out.println("-----------------------------------------------------------------------------------------------------"); |
| 32 | + System.out.println("StudentCountBEtest"); |
| 33 | + Predicate<CourseData> pd = (c -> (c.getDegree().equalsIgnoreCase("BE"))); |
| 34 | + |
| 35 | + long count = cdArray.stream().filter(pd).count(); |
| 36 | + System.out.println("Count of BE Students is :" + count); |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + void StudentCountPlaced() { |
| 41 | + System.out.println("-----------------------------------------------------------------------------------------------------"); |
| 42 | + System.out.println("StudentCountPlaced"); |
| 43 | + Predicate<CourseData> pd = (c -> (c.getPlaced().equalsIgnoreCase("Y"))); |
| 44 | + |
| 45 | + long count = cdArray.stream().filter(pd).count(); |
| 46 | + System.out.println("Count of Number of Students Placed is :" + count); |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + void StudentCountCompletedButNotPlaced() { |
| 51 | + System.out.println("-----------------------------------------------------------------------------------------------------"); |
| 52 | + System.out.println("StudentCountCompletedButNotPlaced"); |
| 53 | + Predicate<CourseData> pd = (c -> (c.getCompleted().equalsIgnoreCase("Y") && !c.getPlaced().equalsIgnoreCase("Y"))); |
| 54 | + |
| 55 | + long count = cdArray.stream().filter(pd).count(); |
| 56 | + System.out.println("Count of Number of Students Who Completed Course But Not Placed is :" + count); |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + void StudentCountNotPlacedAndPlaced() { |
| 61 | + System.out.println("-----------------------------------------------------------------------------------------------------"); |
| 62 | + System.out.println("StudentCountNotPlacedAndPlaced"); |
| 63 | + Predicate<CourseData> pd = (c -> (c.getPlaced().equalsIgnoreCase("Y"))); |
| 64 | + Predicate<CourseData> pd1 = (c -> (!c.getPlaced().equalsIgnoreCase("Y"))); |
| 65 | + |
| 66 | + long count = cdArray.stream().filter(pd).count(); |
| 67 | + System.out.println("Count of Number of Students Placed is :" + count); |
| 68 | + long count1 = cdArray.stream().filter(pd1).count(); |
| 69 | + |
| 70 | + System.out.println("Count of Number of Students NOT Placed is :" + count1); |
| 71 | + } |
| 72 | + |
| 73 | + |
| 74 | + void StudentByName() { |
| 75 | + System.out.println("-----------------------------------------------------------------------------------------------------"); |
| 76 | + System.out.println("StudentSearchByName" + "CLARK"); |
| 77 | + Predicate<CourseData> pd = (c -> (c.getName().contains("CLARK") )); |
| 78 | + |
| 79 | + cdArray.stream().filter(pd).forEach(System.out::println); |
| 80 | + long count = cdArray.stream().filter(pd).count(); |
| 81 | + System.out.println("Count of Number of Students Who Completed Course But Not Placed is :" + count); |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + void StudentNames() { |
| 87 | + System.out.println("-----------------------------------------------------------------------------------------------------"); |
| 88 | + System.out.println("StudentNames" ); |
| 89 | + |
| 90 | + for (CourseData ele : cdArray) { |
| 91 | + System.out.println(ele.getName()); |
| 92 | + } |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + |
| 97 | + void StudentQualAndCount() { |
| 98 | + System.out.println("-----------------------------------------------------------------------------------------------------"); |
| 99 | + System.out.println("StudentQualAndCount" ); |
| 100 | + Map<String, Long> qualCount = new HashMap<String, Long>(); |
| 101 | + qualCount = cdArray.stream().collect(Collectors.groupingBy(CourseData::getDegree, Collectors.counting())); |
| 102 | + System.out.println(qualCount); |
| 103 | + |
| 104 | + } |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + void StudentQualAndScoreInRange() { |
| 109 | + System.out.println("-----------------------------------------------------------------------------------------------------"); |
| 110 | + System.out.println("StudentQualAndScoreInRange" ); |
| 111 | + int lower_range = 80; |
| 112 | + int higher_range = 90; |
| 113 | + |
| 114 | + Predicate<CourseData> pd = (c -> (c.getDegree().equalsIgnoreCase("BE") && c.getScore() >= lower_range && c.getScore() <= higher_range )); |
| 115 | + |
| 116 | + long count = cdArray.stream().filter(pd).count(); |
| 117 | + System.out.println("Count of BE Students Who Scored Between 80 and 90 Percent Is :" + count + " out of " + cdArray.stream().count()); |
| 118 | + |
| 119 | + } |
| 120 | +} |
0 commit comments