Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am getting these errors for getcountgroupbymedia Cannot infer type argument(s) for flatMap(Function super T,? extends Stream extends R>>) gettotalfeesgroupbymedia has errors too and gettotalitemsgroupbymedia

I am getting these errors for getcountgroupbymedia Cannot infer type argument(s) for 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 userDb = new HashMap(); public FuncUtil(Map userDb) { this.userDb = userDb; } public Map getUserDb() { return userDb; } public void addSubscriber(Subscriber subscriber) { Supplier 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 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 printSubscribers(String sortBy) { Function details = p -> p.getName() + " with outstanding amount = " + String.format("%.2f", p.getFees());

Comparator 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 getTotalFeesGroupByMedia() { // Create a new Map to store the total fees for each media type Map 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) -> 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 getCountGroupByMedia() { return userDb.values().stream() .flatMap(subscriber -> subscriber.getMedia().values().stream()) .flatMap(List::stream) .collect(Collectors.groupingBy(MyMedia::getMediaType, Collectors.counting())); }

public Map getTotalItemsGroupByMedia() { return userDb.values().stream() .flatMap(subscriber -> subscriber.getMedia().values().stream()) .flatMap(List::stream) .collect(Collectors.groupingBy(MyMedia::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. // } image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

@override // create subscribers for testing purpose Map Song mapLibSong = new HashMap \langle angle() ; mapLibsong.put( , Arrays. asList(s3, s2, s4)); maplibsong.put(1, Arrays. asList(s1,s2,s3, s4)); mapLibsong.put(2, Arrays.asList(s2,s3, s4, s5)); maplibsong.put(3, Arrays. asList(s3, s5)); maplibsong.put(4, Arrays. asList(s1, s2, s4)); mapLibMovie.put( , Arrays. asList (m3,m2,m4)); mapLibMovie.put(1, Arrays. asList(m1, m2, m3, m4)); maplibMovie.put(2, Arrays. asList (m2, m3)); mapLibMovie.put (3, Arrays. asList (m3, m5)); mapLibMovie.put(4, Arrays. asList(m1, m2, m4)); Map Book mapLibBook = new HashMap \langle angle() ; mapLibBook.put( , Arrays. asList(b3, b2, b4)); mapLibBook.put(1, Arrays.asList(b1, b2, b3, b4)); mapLibBook.put (2, Arrays. asList(b2, b4, b5)); mapLibBook.put (3, Arrays.asList(b3, b5)); mapLibBook.put(4, Arrays. asList(b1, b2, b4)); List listUser = Arrays. asList("Arthur Shelby", "Tommy Shelby", "Ada Shelby", "John Shelby", "Finn Shelby"); List listId = Arrays. asList(" 001 ", "002", "003", " 004 ", "005"); Map userDb = new HashMap \langle angle() ; MyMedia myMedia; for (int i=0;i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions

Question

7. Define cultural space.

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago