SlideShare a Scribd company logo
1 of 12
Download to read offline
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"
+ "-------------------");
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()
{
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";
}
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)
{
// 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()
{
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);
}
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;
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())
{
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();
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
{
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))
{
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].

More Related Content

Similar to Java Question---------------------------FacebookApp(Main).jav.pdf

Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
ICADCMLTPC
 
Java programs
Java programsJava programs
Java programs
jojeph
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdf
stopgolook
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
actocomputer
 
Hello click click boom
Hello click click boomHello click click boom
Hello click click boom
symbian_mgl
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdf
anithareadymade
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
kostikjaylonshaewe47
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
arishmarketing21
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
adityaenterprise32
 

Similar to Java Question---------------------------FacebookApp(Main).jav.pdf (20)

Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Java programs
Java programsJava programs
Java programs
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdf
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab File
 
Manual tecnic sergi_subirats
Manual tecnic sergi_subiratsManual tecnic sergi_subirats
Manual tecnic sergi_subirats
 
Hello click click boom
Hello click click boomHello click click boom
Hello click click boom
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginners
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdf
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
Refer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdfRefer to my progress on this assignment belowIn this problem you w.pdf
Refer to my progress on this assignment belowIn this problem you w.pdf
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
 

More from ambersushil

Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdfJudge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
ambersushil
 
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdfJohn y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
ambersushil
 
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdfJet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
ambersushil
 

More from ambersushil (20)

Juan Williams is a writer with a best selling novel. Juan wishes to .pdf
Juan Williams is a writer with a best selling novel. Juan wishes to .pdfJuan Williams is a writer with a best selling novel. Juan wishes to .pdf
Juan Williams is a writer with a best selling novel. Juan wishes to .pdf
 
Juliets Delivery Services complet� las transacciones proporcionadas.pdf
Juliets Delivery Services complet� las transacciones proporcionadas.pdfJuliets Delivery Services complet� las transacciones proporcionadas.pdf
Juliets Delivery Services complet� las transacciones proporcionadas.pdf
 
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdfJudge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
Judge Mark Griffiths finds that Moodle is a relentless and predatory.pdf
 
Jones, Inc. uses the equity method of accounting for its investment .pdf
Jones, Inc. uses the equity method of accounting for its investment .pdfJones, Inc. uses the equity method of accounting for its investment .pdf
Jones, Inc. uses the equity method of accounting for its investment .pdf
 
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdfJohn y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
John y Sharon celebran un contrato de trabajo, que especifica que Jo.pdf
 
John, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdf
John, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdfJohn, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdf
John, Lesa y Trevor forman una sociedad de responsabilidad limitada..pdf
 
John has recently learned about advance directives in a healthcare l.pdf
John has recently learned about advance directives in a healthcare l.pdfJohn has recently learned about advance directives in a healthcare l.pdf
John has recently learned about advance directives in a healthcare l.pdf
 
Joe�s Ristorant� is a small restaurant near a college campus. It ser.pdf
Joe�s Ristorant� is a small restaurant near a college campus. It ser.pdfJoe�s Ristorant� is a small restaurant near a college campus. It ser.pdf
Joe�s Ristorant� is a small restaurant near a college campus. It ser.pdf
 
Johanna Murray, una activista clim�tica en The National Footprint Fo.pdf
Johanna Murray, una activista clim�tica en The National Footprint Fo.pdfJohanna Murray, una activista clim�tica en The National Footprint Fo.pdf
Johanna Murray, una activista clim�tica en The National Footprint Fo.pdf
 
Joannie est� en la categor�a impositiva del 15. Trabaja para una em.pdf
Joannie est� en la categor�a impositiva del 15. Trabaja para una em.pdfJoannie est� en la categor�a impositiva del 15. Trabaja para una em.pdf
Joannie est� en la categor�a impositiva del 15. Trabaja para una em.pdf
 
Joan accompanies her husband Dan to the clinic and reports to the nu.pdf
Joan accompanies her husband Dan to the clinic and reports to the nu.pdfJoan accompanies her husband Dan to the clinic and reports to the nu.pdf
Joan accompanies her husband Dan to the clinic and reports to the nu.pdf
 
Jim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdf
Jim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdfJim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdf
Jim blindfolds Dwight and gives him a 4lb weight to hold. He then ta.pdf
 
Jill and Jim are married and they have 2 children (Josh and Kenny). .pdf
Jill and Jim are married and they have 2 children (Josh and Kenny). .pdfJill and Jim are married and they have 2 children (Josh and Kenny). .pdf
Jill and Jim are married and they have 2 children (Josh and Kenny). .pdf
 
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdfJet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
Jet blue airways, con sede en Nueva York, hab�a comenzado 2007 en ra.pdf
 
Jerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdf
Jerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdfJerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdf
Jerrold tiene una filosof�a con respecto a la retenci�n de empleados.pdf
 
Jes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdf
Jes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdfJes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdf
Jes�s Mart�nez es un hombre hispano de 46 a�os de su unidad. Ingres�.pdf
 
Jeremiah Restoration Company completed the following selected transa.pdf
Jeremiah Restoration Company completed the following selected transa.pdfJeremiah Restoration Company completed the following selected transa.pdf
Jeremiah Restoration Company completed the following selected transa.pdf
 
Jeremy est� considerando usar mucho el color blanco en el logotipo p.pdf
Jeremy est� considerando usar mucho el color blanco en el logotipo p.pdfJeremy est� considerando usar mucho el color blanco en el logotipo p.pdf
Jeremy est� considerando usar mucho el color blanco en el logotipo p.pdf
 
JenkinsWe have two dozen APIs to deploy, and the dev team was able.pdf
JenkinsWe have two dozen APIs to deploy, and the dev team was able.pdfJenkinsWe have two dozen APIs to deploy, and the dev team was able.pdf
JenkinsWe have two dozen APIs to deploy, and the dev team was able.pdf
 
Jefferson Tutoring had the following payroll information on February.pdf
Jefferson Tutoring had the following payroll information on February.pdfJefferson Tutoring had the following payroll information on February.pdf
Jefferson Tutoring had the following payroll information on February.pdf
 

Recently uploaded

Recently uploaded (20)

Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 

Java Question---------------------------FacebookApp(Main).jav.pdf

  • 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].