java.io.BufferedReader; import java.io.FileReader;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 

        public List<String> 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<String> 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<String> facebookMap;
    private Set<String> 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<String> getAllUsers(){
        List<String> userList = new ArrayList<>();
        Set<String> users = new HashSet<>();
        for(String usersName: facebookMap){
            users.add(usersName);
        }
        userList.addAll(users);
        return userList;
    }

    public List<String> getLikes(String user) {
       
    }
    public List<String> 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

Expert Solution
Step 1

To implement the getLikes and getLikedBy methods, you can use a HashMap to keep track of the likes of each user. The keys of the HashMap would be the users, and the values would be a Set of the users that each user has liked.

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
InputStream
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education