1. Java Question:
---------------------------
FacebookApp(Main).java
---------------------------
import java.util.Scanner;
public class FacebookApp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ProfileOps profileOps = new ProfileOps();
int choice;
do
{
displayMenu();
choice = Integer.parseInt(sc.nextLine().trim());
switch(choice)
{
case 1:
{
System.out.println("nCREATE PROFILE MODULE:n"
+ "----------------------");
profileOps.createProfile();
break;
}
case 2:
{
System.out.println("nSEARCH PROFILE MODULE:n"
+ "----------------------");
profileOps.searchProfile();
break;
}
case 3:
{
System.out.println("nADD FRIENDS MODULE:n"
+ "-------------------");
2. profileOps.addFriends();
break;
}
case 4:
{
System.out.println("nREMOVE FRIENDS MODULE:n"
+ "----------------------");
profileOps.removeFriends();
break;
}
case 5:
{
System.out.println("nUPDATE PROFILE MODULE:n"
+ "----------------------");
profileOps.updateProfile();
break;
}
case 6:
{
System.out.println("nDELETE PROFILE MODULE:n"
+ "----------------------");
profileOps.deleteProfile();
break;
}
case 0:
{
System.out.println("nThanks for using out Social Networking App.n"
+ "Hope to see you soon..Goodbye!n");
System.exit(0);
}
default:
System.out.println("nInvalid selection!n");
}
}while(choice != 0);
}
private static void displayMenu()
3. {
System.out.print("Choose from the options:n"
+ "1. Create profilen"
+ "2. Search for a profilen"
+ "3. Add friendsn"
+ "4. Remove friendsn"
+ "5. Update a profilen"
+ "6. Delete a profilen"
+ "0. Log outn"
+ "Your selection >> ");
}
}
---------------------------
Profile.java
---------------------------
import java.util.ArrayList;
public class Profile {
private String name;
private String status;
private ArrayList friends;
public Profile()
{
this.name = "Guest";
this.status = "Online";
this.friends = new ArrayList<>();
}
public Profile(String name) {
this.name = name;
this.status = "Online";
this.friends = new ArrayList<>();
}
public String getStatus(){ return status; }
public void setOnlineStatus()
{
this.status = "Online";
4. }
public void setOfflineStatus()
{
this.status = "Offline";
}
public void setBusyStatus()
{
this.status = "Busy";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList getFriends() {
return friends;
}
public int getIndexOfFriend(String fName)
{
int index = -1;
for(int i = 0; i < friends.size(); i++)
{
if(friends.get(i).equalsIgnoreCase(fName))
{
index = i;
break;
}
}
return index;
}
public void addFriend(String fName)
{
int index = getIndexOfFriend(fName);
if(index == -1)
{
5. // good to add
friends.add(fName);
System.out.println(fName + " added as a friend.n");
}
else
System.out.println(fName + " is already added as a friend!n");
}
@Override
public String toString()
{
String out = "Profile Name: " + getName() + ", Status: " + getStatus();
if(friends.isEmpty())
return out;
else
{
out += "nFriends: ";
for(int i = 0; i < friends.size(); i++)
{
if(i == friends.size() - 1)
out += friends.get(i);
else
out += friends.get(i) + ", ";
}
return out;
}
}
}
---------------------------
ProfileOps.java
---------------------------
import java.util.ArrayList;
import java.util.Scanner;
public class ProfileOps {
private ArrayList profiles;
public ProfileOps()
6. {
this.profiles = new ArrayList<>();
}
public int getIndexOfProfile(String name)
{
int index = -1;
for(int i = 0; i < profiles.size(); i++)
{
if(profiles.get(i).getName().equalsIgnoreCase(name))
{
index = i;
break;
}
}
return index;
}
public void addFriends()
{
if(profiles.isEmpty())
{
System.out.println("No profiles yet!n");
return;
}
Scanner sc = new Scanner(System.in);
System.out.print("Enter profile name: ");
String pName = sc.nextLine().trim();
int index = getIndexOfProfile(pName);
if(index == -1)
{
System.out.println("There's no such profile named " + pName + "!n");
return;
}
System.out.print("Enter the name of the friend: ");
String fName = sc.nextLine().trim();
profiles.get(index).addFriend(fName);
}
7. public void createProfile()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter profile name: ");
String pName = sc.nextLine().trim();
int index = getIndexOfProfile(pName);
if(index == -1)
{
// profile not present, can add it
Profile profile = new Profile(pName);
System.out.print("Enter profile status:n"
+ "1. Onlinen"
+ "2. Offlinen"
+ "3. Busyn"
+ "Enter >> ");
int stChoice = Integer.parseInt(sc.nextLine().trim());
while (stChoice != 1 && stChoice != 2 && stChoice != 3) {
System.out.println("Invalid status choice!n");
System.out.print("Enter profile status:n"
+ "1. Onlinen"
+ "2. Offlinen"
+ "3. Busyn"
+ "Enter >> ");
stChoice = Integer.parseInt(sc.nextLine().trim());
}
if (stChoice == 1) {
profile.setOnlineStatus();
} else if (stChoice == 2) {
profile.setOfflineStatus();
} else if (stChoice == 3) {
profile.setBusyStatus();
} else {
profile.setOfflineStatus();
}
System.out.println("Profile status set to " + profile.getStatus() + ".");
char yesNo;
8. do
{
System.out.print("Add friend? [y/n]: ");
yesNo = sc.nextLine().trim().charAt(0);
if(yesNo == 'N' || yesNo == 'n')
break;
else
{
System.out.print("Name of the friend: ");
String fName = sc.nextLine().trim();
profile.addFriend(fName);
}
}while(yesNo != 'N' || yesNo != 'n');
profiles.add(profile);
System.out.println("Profile has been created for " + pName + ".n");
}
}
public void searchProfile()
{
if(profiles.isEmpty())
{
System.out.println("No profiles yet!n");
return;
}
Scanner sc = new Scanner(System.in);
System.out.print("Enter profile name to search: ");
String pName = sc.nextLine().trim();
int index = getIndexOfProfile(pName);
if(index == -1)
System.out.println("Sorry, there's no such profile named " + pName + "!n");
else
System.out.println("Match found:n" + profiles.get(index) + "n");
}
public void updateProfile()
{
if(profiles.isEmpty())
9. {
System.out.println("No profiles yet!n");
return;
}
Scanner sc = new Scanner(System.in);
System.out.print("Enter profile name to search: ");
String pName = sc.nextLine().trim();
int index = getIndexOfProfile(pName);
if(index == -1)
System.out.println("Sorry, there's no such profile named " + pName + "!n");
else
{
// update the profile
System.out.print("Enter new name for the profile: ");
String newPName = sc.nextLine().trim();
profiles.get(index).setName(newPName);
System.out.print("Enter profile status:n"
+ "1. Onlinen"
+ "2. Offlinen"
+ "3. Busyn"
+ "Enter >> ");
int stChoice = Integer.parseInt(sc.nextLine().trim());
while(stChoice != 1 && stChoice != 2 && stChoice != 3)
{
System.out.println("Invalid status choice!n");
System.out.print("Enter profile status:n"
+ "1. Onlinen"
+ "2. Offlinen"
+ "3. Busyn"
+ "Enter >> ");
stChoice = Integer.parseInt(sc.nextLine().trim());
}
if(stChoice == 1)
profiles.get(index).setOnlineStatus();
else if(stChoice == 2)
profiles.get(index).setOfflineStatus();
10. else if(stChoice == 3)
profiles.get(index).setBusyStatus();
else
profiles.get(index).setOfflineStatus();
char yesNo;
do
{
System.out.print("Add friend? [y/n]: ");
yesNo = sc.nextLine().trim().charAt(0);
if(yesNo == 'N' || yesNo == 'n')
break;
else
{
System.out.print("Name of the friend: ");
String fName = sc.nextLine().trim();
profiles.get(index).addFriend(fName);
System.out.println();
}
}while(yesNo != 'N' || yesNo != 'n');
System.out.println("Profile updated successfully.n");
}
}
public void deleteProfile()
{
if(profiles.isEmpty())
{
System.out.println("No profiles yet!n");
return;
}
Scanner sc = new Scanner(System.in);
System.out.print("Enter profile name to search: ");
String pName = sc.nextLine().trim();
int index = getIndexOfProfile(pName);
if(index == -1)
System.out.println("Sorry, there's no such profile named " + pName + "!n");
else
11. {
profiles.remove(index);
System.out.println("Profile for " + pName + " is deleted successfully.n");
}
}
public void removeFriends()
{
if(profiles.isEmpty())
{
System.out.println("No profiles yet!n");
return;
}
Scanner sc = new Scanner(System.in);
System.out.print("Enter profile name to search: ");
String pName = sc.nextLine().trim();
int index = getIndexOfProfile(pName);
if(index == -1)
System.out.println("Sorry, there's no such profile named " + pName + "!n");
else
{
ArrayList friends = profiles.get(index).getFriends();
System.out.println("There are " + friends.size() + " friends.");
for(int i = 0; i < friends.size(); i++)
{
if(i == friends.size() - 1)
System.out.println(friends.get(i));
else
System.out.print(friends.get(i) + ", ");
}
System.out.print("Enter the name of the friend to remove: ");
String fName = sc.nextLine().trim();
int c = 0;
for(int i = 0; i < friends.size(); i++)
{
if(friends.get(i).equalsIgnoreCase(fName))
{
12. friends.remove(i);
c++;
}
}
if(c == 0)
System.out.println("Sorry, there's no such friend named " + fName + "!n");
else
System.out.println("Total " + c + " friend(s) were removed.n");
}
}
} Important: 1. You should submit all files you used in your program (Please do not zip them) 2.
Name your diver (main) file "Driver". I need this file to run your code and test it. 3. You should
submit the UML for your program started from your driver (main) file. Data Abstract &
Structures - CIS 22C Final Project The popular social network Facebook TM was founded by
Mark Zuckerberg and his classmates at Harvard University in 2004 . At the time, he was a
sophomore studying computer science. You already did this part for your midterm part 1: Design
and implement an application that maintains the data for a simple social network. Each person in
the network should have a profile that contains the person's name, an image(optional), current
status, and a list of friends. Your application should allow a user to join the network, leave the
network, create a profile, modify the profile, search for other profiles, and add friends. Repeat
the Project above to create a simple social network. Use a graph to track friend relationships
among members of the network. Add a feature to enable people to see a list of their friends'
friends. Reference: Data Structures and Abstractions with Java, Frank M. Carrano, 4th Edition,
Pearson, 2015. [Graph Implementations].