Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public List getLikes(String user) This will take a String representing a user (like Mike) and return a unique List containing all of the users that

public List getLikes(String user)

This will take a String representing a user (like Mike) and return a unique List containing all of the users that have liked the user Mike.

public List getLikedBy(String user)

This will take a String representing a user (like Tony) and return a unique List containing each user that Tony has liked.

create a Main to test your work.

import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set;

public class FacebookLikeManager { public List facebookMap; private Set likesSets;

public FacebookLikeManager() { facebookMap = new ArrayList<>(); likesSets = new HashSet<>(Arrays.asList("Mike","Kristen","Bill","Sara")); }

public void buildMap(String filePath) { try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { String line = reader.readLine();

while (line != null) { String[] lineWords = line.split("[\\s,%$]+"); for (String word : lineWords) {

String cleanWord = word.replaceAll("[^A-Za-z]", "").toUpperCase(); facebookMap.add(cleanWord); } line = reader.readLine(); }

} catch (IOException ex) { System.err.format("IOException: %s%n", ex); } }

public List getAllUsers(){ List userList = new ArrayList<>(); Set users = new HashSet<>(); for(String usersName: facebookMap){ users.add(usersName); } userList.addAll(users); return userList; }

public List getLikes(String user) { } public List getLikedBy(String user) { }

}

public class Main {

public static void main(String[] args) {

FacebookLikeManager main = new FacebookLikeManager();

main.buildMap(args[0]);

System.out.println(main.getAllUsers());

}

}

users.txt

Mike: Kristen, Sara, Nate, Anthony, Randy Kristen: Mike, John, Steve, Bill Bill: Sara, Nate Sara: Nate, Anthony

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

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions