-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumOsalByNameSmith.java
More file actions
44 lines (32 loc) · 1.13 KB
/
Copy pathSumOsalByNameSmith.java
File metadata and controls
44 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* // 30. Find the Sum of Salaries for Employees with Names Containing "Smith":
// - Calculate the sum of salaries for employees whose names contain the
substring "Smith."
System.out.println(RED+"******* Calculate the sum of salaries for employees
whose names contain the substring Smith***"+RESET);
double sum2 =
list.stream().filter(k->k.getName().contains("Smith")).mapToDouble(k->k.getSalary()).sum();
System.out.println(sum2);
*/
package Day3;
import java.util.stream.Collectors;
import Day1.EmployeeAdder;
public class SumOsalByNameSmith {
public static void main(String[] args)
{
EmployeeAdder emp= new EmployeeAdder();
emp.addDetails().stream().collect(Collectors.groupingBy(s->{
if(s.getName().equals("Smith"))
{
return s.getName();
}
else
{
return "null";
}
})).forEach((k,v)->System.out.println(k!="null"?k+" "+v:" "));
System.out.println("------------------------------");
double tot= emp.addDetails().stream().filter(k->k.getName().equals("Smith")).mapToDouble(t->t.getSalary()).sum();
System.out.println(tot);
}
}