Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

FriendList This class has one attribute – allUsers (a Linkedlist of Nodes that s

ID: 3678390 • Letter: F

Question

FriendList

This class has one attribute – allUsers (a Linkedlist of Nodes that stores Users).

It also can implement the following methods:

• FriendList( ): //no args constructor that creates a new empty list

• addUser (User u) : void //adds a user after checking that they are at least 13 years old and do not already exist

• removeUser (User u ) : void //remove user from FriendList and remove that user as a friend of any other users

• totalUsers ( ) : int //returns the total number of users on FriendList

• getUsers () : LinkedList //returns the list of all users

• mostFriends ( ) : User //returns the user who has the most friends. If two or more users have the 'most friends' (i.e., a tie for most friends, return the first User with that number (similar to how ArrayLists handle this case)

• oldestFriend() : User //returns the user with the oldest friend. If two or more users have 'the oldest' friend (i.e., same birthday – return the first User (similar to how ArrayLists handle this case)

• commonFriends (User, User): LinkedList //find common friends between users and returns new list

User

Attributes:

String name

String location //this is where they currently live (city or town)

int birthYear LinkedList friends //this is a

LinkedList that holds Nodes of Users who are their friends

It implements the following methods:

• User (String, String, int): //set name, location and birthYear, initialize the LinkedList

• getName ( ) : String

• getLocation ( ) : String

• getBirthYear ( ) : int

• isEqual (User) : boolean

• getFriends ( ) : LinkedList

• getNumFriends ( ) : int //returns the number of friends the user has

• toString ( ) : String //returns the name and location of the user

• addFriend (User) : void //adds a friend to their list

• removeFriend (User) : void //removes a friend from their list

• oldestFriend ( ) : User //returns the friend who is the oldest (e.g., 30 years old). If there is tie (i.e., same birthday) return the first friend with that birthdate.

Explanation / Answer

import java.io.*;

import java.util.*;

public class FriendList(() {

public static void main(String args[]) throws Exception {

int user ,n;

Node link = NULL;

public void FriendList() {

LinkedList l = new LinkedList(); }

public void allUsers(User u) {

user = u;

link = n; }

public void addUser(User u) {

l.add(u); }

public void removeUser(User u) {

l.remove(u);

Boolean remove(User u) {

l.remove(u); }}

public void totalUsers() {

System.out.println(“total no of users”,link);

return user;

return link;

}

public void getUsers() {

return user; }

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String name,location;

int birthyear,birthday,int age;

public void User(String name,String location,int birthyear,int birthdate) {

System.out.println(“Enter user name:”);

name = br.readLine();

System.out.println(“Enter Location:”);

location = br.readLine();

System.out.println(“Enter year of birth:”);

l.birthyear = br.readLine();

System.out.println(“Enter date of birth:”);

l.birthdate = br.readLine();

System.out.println(“Enter age :”);

age = br.readLine(); }

public void getName(String name) {

return name; }

public void getLocation(String location) {

return location; }

public void getBirthYear(int birthyear) {

return birthyear; }

boolean isEqual(User u) {

return true; }

public getFriends() {

l.user();

return user; }

public getNumFriends() {

l.link();

return link; }

public String toString() {

return “Name:” + name + “Location:” + location;

}

public void addFriend(User u) {

l.add(u);

return link; }

public void removeFriend(User u) {

l.remove(u); }

public void oldestFriend() {

if(u.age >= 30) {

return user;

for(int i: 1 to 10) {

else if(oldestuser = u.birthdate(.equals)ui.birthdate) {

return oldestUser; } }

public void mostFriends() {

if(u.FriendList() >2 )

return link;

for(int i: 1 to 10) {

else if ( n = u.FriendList(). compareTo(ui.FriendList()) {

return getNumFriends()/return n;

}

public void commonFriends( String name,User u) {

public static <T> T commonFriends(FriendsList <T> list) {

Map <T, String> map new HashMap<>();

for (T t : list) {

String str = map.get(t);

map.put(t,str ==null ? 1: str +1);

}

Entry<T,String> max = null;

for(Entry<T, string> e: map.allUsers()) {

if (max ==null || e.getString() > max.getString())

max = e;

else e=max;

}

return max;

} }

} }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote