SlideShare a Scribd company logo
1 of 5
I am getting these errors for getcountgroupbymedia Cannot infer type argument(s) for <R>
flatMap(Function<? super T,? extends Stream<? extends R>>)
gettotalfeesgroupbymedia has errors too and gettotalitemsgroupbymedia kindly could you solve
it and replace it with the correct code
package adminSite;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import yourPrime.*;
public class FuncUtil {
private Map<String, Subscriber> userDb = new HashMap<>();
public FuncUtil(Map<String, Subscriber> userDb) {
this.userDb = userDb;
}
public Map<String, Subscriber> getUserDb() {
return userDb;
}
public void addSubscriber(Subscriber subscriber) {
Supplier<String> userId = () -> generateId().toString();
String id = userId.get();
subscriber.setUserID(id);
userDb.putIfAbsent(id, subscriber);
}
public Integer generateId() {
return new Random().nextInt(80000);
}
public boolean modifyPassword(String userId, String newPassword) {
Subscriber subscriber = userDb.get(userId);
subscriber.setPassword(newPassword);
userDb.replace(userId, subscriber);
if (userDb.get(userId).getPassword().equals(newPassword))
return true;
else
return false;
}
public boolean deleteSubscriber(String userId) {
userDb.remove(userId);
if (userDb.get(userId) == null)
return true;
else
return false;
}
// TODO refactor the implementation of the searchSubscriber() method using Java 8 stream
// and lambda expression. You can also use the existing interfaces if you prefer (but not
required).
//
public List<Subscriber> searchSubscriber(String keyword) {
return userDb.values().stream()
.filter(subscriber -> subscriber.getName().contains(keyword) ||
subscriber.getUserID().contains(keyword))
.collect(Collectors.toList());
}
// TODO refactor the implementation of the total sum of fees calculation using Java 8 streams
// and lambda expression. You can also use the exisiting interfaces if you prefer (but not
required).
//
public double calculateOverdueFees() {
return userDb.values().stream()
.mapToDouble(Subscriber::getFees)
.sum();
}
// TODO refactor the implementation of the printAllSubscriber() method here with Java 8 stream
and method
// reference. You MUST use the function interface already defined here. The method will also
print out the
// details according to the sort by option - name of the subscriber, and the outstanding fees.
//
public void printAllSubscribers(String sortBy) {
Function<Subscriber, String> details = p -> p.getName() + " with outstanding amount = " +
String.format("%.2f", p.getFees());
Comparator<Subscriber> comparator;
if (sortBy.equals("name")) {
comparator = Comparator.comparing(Subscriber::getName);
} else if (sortBy.equals("fees")) {
comparator = Comparator.comparing(Subscriber::getFees);
} else {
throw new IllegalArgumentException("Invalid sort by option");
}
userDb.values().stream()
.sorted(comparator)
.map(details)
.forEach(System.out::println);
}
// TODO create a method to return the average outstanding fees from all accounts using Java 8
stream and lambda expression.
//
public double getAverageOutstanding() {
return userDb.values().stream()
.mapToDouble(Subscriber::getFees)
.average()
.orElse(0);
}
// TODO create a method to return the outstanding fees from all accounts group by the media
type.
// You should make use of Java 8 Streams and lambda expression to do this - return map
//
public Map<String, Double> getTotalFeesGroupByMedia() {
// Create a new Map to store the total fees for each media type
Map<String, Double> totalFees = new HashMap<>();
// Loop through each media type
for (MyMedia.Media media : MyMedia.Media.values()) {
// Compute the total fees for the current media type
Double fees = userDb.values().stream()
.flatMap(subscriber -> subscriber.getMedia().get(media).stream())
.mapToDouble(MyMedia::getFees)
.sum();
// Store the total fees for the current media type in the Map
totalFees.put(media.toString(), fees);
}
// Return the Map of total fees for each media type
return totalFees;
}
public Map<String, Long> getCountGroupByMedia() {
// Create a new Map to store the item counts for each media type
Map<String, Long> itemCounts = new HashMap<>();
// Loop through each media type
for (MyMedia.Media media : MyMedia.Media.values()) {
// Count the number of items for the current media type
Long count = userDb.values().stream()
.flatMap(subscriber -> subscriber.getMedia().get(media).stream()).count();
// Store the item count for the current media type in the Map
itemCounts.put(media.toString(), count);
}
// Return the Map of item counts for each media type
return itemCounts;
}
public Map<MediaType, Long> getTotalItemsGroupByMedia() {
return accounts.stream()
.flatMap(account -> account.getItems().stream())
.collect(Collectors.groupingBy(List::getMediaType, Collectors.counting()));
}
// TODO create a method to return the total number of items from all accounts using Java 8
streams and lambda expression.
// group by the media type. Use the programming logic (idioms) that you've implemented in the
getTotalFeesGroupByMedia()
// method as a source of inspiration in completing this method.
//
}
@override

More Related Content

Similar to Solve Java 8 stream errors get count and totals by media

documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...Akaks
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesGanesh Samarthyam
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06HUST
 
Apache Hadoop Java API
Apache Hadoop Java APIApache Hadoop Java API
Apache Hadoop Java APIAdam Kawa
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)Giuseppe Filograno
 
Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)RichardWarburton
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Flink Forward
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0Matt Raible
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfANJALIENTERPRISES1
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignmentzjkdg986
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignmentfdjfjfy4498
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignmentsdfgsdg36
 

Similar to Solve Java 8 stream errors get count and totals by media (20)

CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
 
Wien15 java8
Wien15 java8Wien15 java8
Wien15 java8
 
Apache Hadoop Java API
Apache Hadoop Java APIApache Hadoop Java API
Apache Hadoop Java API
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)
 
Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
 
Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
 
basic concepts
basic conceptsbasic concepts
basic concepts
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
 

More from PaulntmMilleri

III- EXERCISE 1- CALCULATING ALLELIC- GENOTYPIC- AND PHENOTYPIC FREQUE.docx
III- EXERCISE 1- CALCULATING ALLELIC- GENOTYPIC- AND PHENOTYPIC FREQUE.docxIII- EXERCISE 1- CALCULATING ALLELIC- GENOTYPIC- AND PHENOTYPIC FREQUE.docx
III- EXERCISE 1- CALCULATING ALLELIC- GENOTYPIC- AND PHENOTYPIC FREQUE.docxPaulntmMilleri
 
If your answer does not contain the proper ER Diagram- you will get a.docx
If your answer does not contain the proper ER Diagram- you will get a.docxIf your answer does not contain the proper ER Diagram- you will get a.docx
If your answer does not contain the proper ER Diagram- you will get a.docxPaulntmMilleri
 
If you want to create a layout for two buttons side by side on a windo.docx
If you want to create a layout for two buttons side by side on a windo.docxIf you want to create a layout for two buttons side by side on a windo.docx
If you want to create a layout for two buttons side by side on a windo.docxPaulntmMilleri
 
If P(B)-0-8- find P(BC)-.docx
If P(B)-0-8- find P(BC)-.docxIf P(B)-0-8- find P(BC)-.docx
If P(B)-0-8- find P(BC)-.docxPaulntmMilleri
 
If the GDP deflator is 400 and nominal GDP is $2 trillion billion- wha.docx
If the GDP deflator is 400 and nominal GDP is $2 trillion billion- wha.docxIf the GDP deflator is 400 and nominal GDP is $2 trillion billion- wha.docx
If the GDP deflator is 400 and nominal GDP is $2 trillion billion- wha.docxPaulntmMilleri
 
If event A-0-72 then the complement of event A-.docx
If event A-0-72 then the complement of event A-.docxIf event A-0-72 then the complement of event A-.docx
If event A-0-72 then the complement of event A-.docxPaulntmMilleri
 
If the Earth's orbit around the Sun was a perfect circle instead of an.docx
If the Earth's orbit around the Sun was a perfect circle instead of an.docxIf the Earth's orbit around the Sun was a perfect circle instead of an.docx
If the Earth's orbit around the Sun was a perfect circle instead of an.docxPaulntmMilleri
 
If I have 1-5 million dollars as a loan to start my own company and I.docx
If I have 1-5 million dollars as a loan to start my own company and I.docxIf I have 1-5 million dollars as a loan to start my own company and I.docx
If I have 1-5 million dollars as a loan to start my own company and I.docxPaulntmMilleri
 
If France and Korea engage in substantial trade but little financial f.docx
If France and Korea engage in substantial trade but little financial f.docxIf France and Korea engage in substantial trade but little financial f.docx
If France and Korea engage in substantial trade but little financial f.docxPaulntmMilleri
 
If a method overloads another method- can the two methods have differe.docx
If a method overloads another method- can the two methods have differe.docxIf a method overloads another method- can the two methods have differe.docx
If a method overloads another method- can the two methods have differe.docxPaulntmMilleri
 
If Assets equal $150 and Liabilities equal $30- what does Owner's Equi.docx
If Assets equal $150 and Liabilities equal $30- what does Owner's Equi.docxIf Assets equal $150 and Liabilities equal $30- what does Owner's Equi.docx
If Assets equal $150 and Liabilities equal $30- what does Owner's Equi.docxPaulntmMilleri
 
If a random variable X is uniformly distributed between 0 and 5 - what.docx
If a random variable X is uniformly distributed between 0 and 5 - what.docxIf a random variable X is uniformly distributed between 0 and 5 - what.docx
If a random variable X is uniformly distributed between 0 and 5 - what.docxPaulntmMilleri
 
If a corpus contains 10-000 documents- and a search query retrieves 10.docx
If a corpus contains 10-000 documents- and a search query retrieves 10.docxIf a corpus contains 10-000 documents- and a search query retrieves 10.docx
If a corpus contains 10-000 documents- and a search query retrieves 10.docxPaulntmMilleri
 
I- Explain this abstract and use some key points to use review some co.docx
I- Explain this abstract and use some key points to use review some co.docxI- Explain this abstract and use some key points to use review some co.docx
I- Explain this abstract and use some key points to use review some co.docxPaulntmMilleri
 
Identify the structure located at the point marked H- Do not give the.docx
Identify the structure located at the point marked H- Do not give the.docxIdentify the structure located at the point marked H- Do not give the.docx
Identify the structure located at the point marked H- Do not give the.docxPaulntmMilleri
 
Identify different aspects of organisational culture in some contempor.docx
Identify different aspects of organisational culture in some contempor.docxIdentify different aspects of organisational culture in some contempor.docx
Identify different aspects of organisational culture in some contempor.docxPaulntmMilleri
 
Identify and describe two ways that non-imaging providers- such as phy.docx
Identify and describe two ways that non-imaging providers- such as phy.docxIdentify and describe two ways that non-imaging providers- such as phy.docx
Identify and describe two ways that non-imaging providers- such as phy.docxPaulntmMilleri
 
Ibrahim is able to lend money to Naif (direct finance) with higher int.docx
Ibrahim is able to lend money to Naif (direct finance) with higher int.docxIbrahim is able to lend money to Naif (direct finance) with higher int.docx
Ibrahim is able to lend money to Naif (direct finance) with higher int.docxPaulntmMilleri
 
ib - ifpenata-1Journal Entries for Purchase- Return- and Remittance-Pe.docx
ib - ifpenata-1Journal Entries for Purchase- Return- and Remittance-Pe.docxib - ifpenata-1Journal Entries for Purchase- Return- and Remittance-Pe.docx
ib - ifpenata-1Journal Entries for Purchase- Return- and Remittance-Pe.docxPaulntmMilleri
 
I've also gathered a list of the primary selling features that Lavish.docx
I've also gathered a list of the primary selling features that Lavish.docxI've also gathered a list of the primary selling features that Lavish.docx
I've also gathered a list of the primary selling features that Lavish.docxPaulntmMilleri
 

More from PaulntmMilleri (20)

III- EXERCISE 1- CALCULATING ALLELIC- GENOTYPIC- AND PHENOTYPIC FREQUE.docx
III- EXERCISE 1- CALCULATING ALLELIC- GENOTYPIC- AND PHENOTYPIC FREQUE.docxIII- EXERCISE 1- CALCULATING ALLELIC- GENOTYPIC- AND PHENOTYPIC FREQUE.docx
III- EXERCISE 1- CALCULATING ALLELIC- GENOTYPIC- AND PHENOTYPIC FREQUE.docx
 
If your answer does not contain the proper ER Diagram- you will get a.docx
If your answer does not contain the proper ER Diagram- you will get a.docxIf your answer does not contain the proper ER Diagram- you will get a.docx
If your answer does not contain the proper ER Diagram- you will get a.docx
 
If you want to create a layout for two buttons side by side on a windo.docx
If you want to create a layout for two buttons side by side on a windo.docxIf you want to create a layout for two buttons side by side on a windo.docx
If you want to create a layout for two buttons side by side on a windo.docx
 
If P(B)-0-8- find P(BC)-.docx
If P(B)-0-8- find P(BC)-.docxIf P(B)-0-8- find P(BC)-.docx
If P(B)-0-8- find P(BC)-.docx
 
If the GDP deflator is 400 and nominal GDP is $2 trillion billion- wha.docx
If the GDP deflator is 400 and nominal GDP is $2 trillion billion- wha.docxIf the GDP deflator is 400 and nominal GDP is $2 trillion billion- wha.docx
If the GDP deflator is 400 and nominal GDP is $2 trillion billion- wha.docx
 
If event A-0-72 then the complement of event A-.docx
If event A-0-72 then the complement of event A-.docxIf event A-0-72 then the complement of event A-.docx
If event A-0-72 then the complement of event A-.docx
 
If the Earth's orbit around the Sun was a perfect circle instead of an.docx
If the Earth's orbit around the Sun was a perfect circle instead of an.docxIf the Earth's orbit around the Sun was a perfect circle instead of an.docx
If the Earth's orbit around the Sun was a perfect circle instead of an.docx
 
If I have 1-5 million dollars as a loan to start my own company and I.docx
If I have 1-5 million dollars as a loan to start my own company and I.docxIf I have 1-5 million dollars as a loan to start my own company and I.docx
If I have 1-5 million dollars as a loan to start my own company and I.docx
 
If France and Korea engage in substantial trade but little financial f.docx
If France and Korea engage in substantial trade but little financial f.docxIf France and Korea engage in substantial trade but little financial f.docx
If France and Korea engage in substantial trade but little financial f.docx
 
If a method overloads another method- can the two methods have differe.docx
If a method overloads another method- can the two methods have differe.docxIf a method overloads another method- can the two methods have differe.docx
If a method overloads another method- can the two methods have differe.docx
 
If Assets equal $150 and Liabilities equal $30- what does Owner's Equi.docx
If Assets equal $150 and Liabilities equal $30- what does Owner's Equi.docxIf Assets equal $150 and Liabilities equal $30- what does Owner's Equi.docx
If Assets equal $150 and Liabilities equal $30- what does Owner's Equi.docx
 
If a random variable X is uniformly distributed between 0 and 5 - what.docx
If a random variable X is uniformly distributed between 0 and 5 - what.docxIf a random variable X is uniformly distributed between 0 and 5 - what.docx
If a random variable X is uniformly distributed between 0 and 5 - what.docx
 
If a corpus contains 10-000 documents- and a search query retrieves 10.docx
If a corpus contains 10-000 documents- and a search query retrieves 10.docxIf a corpus contains 10-000 documents- and a search query retrieves 10.docx
If a corpus contains 10-000 documents- and a search query retrieves 10.docx
 
I- Explain this abstract and use some key points to use review some co.docx
I- Explain this abstract and use some key points to use review some co.docxI- Explain this abstract and use some key points to use review some co.docx
I- Explain this abstract and use some key points to use review some co.docx
 
Identify the structure located at the point marked H- Do not give the.docx
Identify the structure located at the point marked H- Do not give the.docxIdentify the structure located at the point marked H- Do not give the.docx
Identify the structure located at the point marked H- Do not give the.docx
 
Identify different aspects of organisational culture in some contempor.docx
Identify different aspects of organisational culture in some contempor.docxIdentify different aspects of organisational culture in some contempor.docx
Identify different aspects of organisational culture in some contempor.docx
 
Identify and describe two ways that non-imaging providers- such as phy.docx
Identify and describe two ways that non-imaging providers- such as phy.docxIdentify and describe two ways that non-imaging providers- such as phy.docx
Identify and describe two ways that non-imaging providers- such as phy.docx
 
Ibrahim is able to lend money to Naif (direct finance) with higher int.docx
Ibrahim is able to lend money to Naif (direct finance) with higher int.docxIbrahim is able to lend money to Naif (direct finance) with higher int.docx
Ibrahim is able to lend money to Naif (direct finance) with higher int.docx
 
ib - ifpenata-1Journal Entries for Purchase- Return- and Remittance-Pe.docx
ib - ifpenata-1Journal Entries for Purchase- Return- and Remittance-Pe.docxib - ifpenata-1Journal Entries for Purchase- Return- and Remittance-Pe.docx
ib - ifpenata-1Journal Entries for Purchase- Return- and Remittance-Pe.docx
 
I've also gathered a list of the primary selling features that Lavish.docx
I've also gathered a list of the primary selling features that Lavish.docxI've also gathered a list of the primary selling features that Lavish.docx
I've also gathered a list of the primary selling features that Lavish.docx
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 

Solve Java 8 stream errors get count and totals by media

  • 1. I am getting these errors for getcountgroupbymedia Cannot infer type argument(s) for <R> flatMap(Function<? super T,? extends Stream<? extends R>>) gettotalfeesgroupbymedia has errors too and gettotalitemsgroupbymedia kindly could you solve it and replace it with the correct code package adminSite; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; import yourPrime.*; public class FuncUtil { private Map<String, Subscriber> userDb = new HashMap<>(); public FuncUtil(Map<String, Subscriber> userDb) { this.userDb = userDb; } public Map<String, Subscriber> getUserDb() { return userDb; } public void addSubscriber(Subscriber subscriber) { Supplier<String> userId = () -> generateId().toString(); String id = userId.get(); subscriber.setUserID(id); userDb.putIfAbsent(id, subscriber); } public Integer generateId() { return new Random().nextInt(80000); } public boolean modifyPassword(String userId, String newPassword) { Subscriber subscriber = userDb.get(userId); subscriber.setPassword(newPassword);
  • 2. userDb.replace(userId, subscriber); if (userDb.get(userId).getPassword().equals(newPassword)) return true; else return false; } public boolean deleteSubscriber(String userId) { userDb.remove(userId); if (userDb.get(userId) == null) return true; else return false; } // TODO refactor the implementation of the searchSubscriber() method using Java 8 stream // and lambda expression. You can also use the existing interfaces if you prefer (but not required). // public List<Subscriber> searchSubscriber(String keyword) { return userDb.values().stream() .filter(subscriber -> subscriber.getName().contains(keyword) || subscriber.getUserID().contains(keyword)) .collect(Collectors.toList()); } // TODO refactor the implementation of the total sum of fees calculation using Java 8 streams // and lambda expression. You can also use the exisiting interfaces if you prefer (but not required). // public double calculateOverdueFees() { return userDb.values().stream() .mapToDouble(Subscriber::getFees) .sum(); } // TODO refactor the implementation of the printAllSubscriber() method here with Java 8 stream and method // reference. You MUST use the function interface already defined here. The method will also print out the // details according to the sort by option - name of the subscriber, and the outstanding fees. // public void printAllSubscribers(String sortBy) { Function<Subscriber, String> details = p -> p.getName() + " with outstanding amount = " + String.format("%.2f", p.getFees());
  • 3. Comparator<Subscriber> comparator; if (sortBy.equals("name")) { comparator = Comparator.comparing(Subscriber::getName); } else if (sortBy.equals("fees")) { comparator = Comparator.comparing(Subscriber::getFees); } else { throw new IllegalArgumentException("Invalid sort by option"); } userDb.values().stream() .sorted(comparator) .map(details) .forEach(System.out::println); } // TODO create a method to return the average outstanding fees from all accounts using Java 8 stream and lambda expression. // public double getAverageOutstanding() { return userDb.values().stream() .mapToDouble(Subscriber::getFees) .average() .orElse(0); } // TODO create a method to return the outstanding fees from all accounts group by the media type. // You should make use of Java 8 Streams and lambda expression to do this - return map // public Map<String, Double> getTotalFeesGroupByMedia() { // Create a new Map to store the total fees for each media type Map<String, Double> totalFees = new HashMap<>(); // Loop through each media type for (MyMedia.Media media : MyMedia.Media.values()) { // Compute the total fees for the current media type Double fees = userDb.values().stream() .flatMap(subscriber -> subscriber.getMedia().get(media).stream()) .mapToDouble(MyMedia::getFees) .sum();
  • 4. // Store the total fees for the current media type in the Map totalFees.put(media.toString(), fees); } // Return the Map of total fees for each media type return totalFees; } public Map<String, Long> getCountGroupByMedia() { // Create a new Map to store the item counts for each media type Map<String, Long> itemCounts = new HashMap<>(); // Loop through each media type for (MyMedia.Media media : MyMedia.Media.values()) { // Count the number of items for the current media type Long count = userDb.values().stream() .flatMap(subscriber -> subscriber.getMedia().get(media).stream()).count(); // Store the item count for the current media type in the Map itemCounts.put(media.toString(), count); } // Return the Map of item counts for each media type return itemCounts; } public Map<MediaType, Long> getTotalItemsGroupByMedia() { return accounts.stream() .flatMap(account -> account.getItems().stream()) .collect(Collectors.groupingBy(List::getMediaType, Collectors.counting())); } // TODO create a method to return the total number of items from all accounts using Java 8 streams and lambda expression. // group by the media type. Use the programming logic (idioms) that you've implemented in the getTotalFeesGroupByMedia() // method as a source of inspiration in completing this method. // }