Please using Java to do the following project The first part is related to topic
ID: 3905965 • Letter: P
Question
Please using Java to do the following project
The first part is related to topic: A List Implementation That Uses an Array
The second part is related to topic: Graph Implementations
Feel free to use any data structure as needed.
Once finished, you can either paste the code here or send me a link on github.
Please don't put all classes and functions in one file, separate them in different java files, Thanks:)
Design and implement an application that maintains the data for a simple social network. Eaclh person in the network should have a profile that contains the person's name, optional image, 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, scarch for other profiles, and add friends.Explanation / Answer
import java.io.*;
import java.util.*;
class Member {
private String name;
private String currentStatus;
private Member next;
public Member(String n){
name = n;
currentStatus = "Active";
next = null;
}
String getName(){
return name;
}
String getStatus(){
return currentStatus;
}
public void setStatus(String a){
currentStatus = a;
}
public void setName(String a){
name = a;
}
public void addFriend (String a){
Member m = new Member(a);
if (next == null){
next = m;
}
else {
Member p = next;
while (p.next != null)
p = p.next;
p.next = m;
}
}
public void displayFriends (){
if (next == null){
System.out.println("No friends");
}
else {
Member p = next;
while (p!= null){
System.out.println(p.getName());
p = p.next;
}
}
}
}
class UserDatabase{
private ArrayList<Member> list;
public UserDatabase(){
list = new ArrayList<Member>();
}
public void addMember(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter name:");
String line = sc.nextLine();
Member m = new Member(line);
list.add(m);
}
public void removeMember(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter name:");
String line = sc.nextLine();
int found = 0;
for (int i = 0; i < list.size();i++){
if (list.get(i).getName().equals(line)){
list.remove(i);
found = 1;
}
}
if (found == 0){
System.out.println("Not Found");
}
}
public void searchMember(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter name:");
String line = sc.nextLine();
int found = 0;
for (int i = 0; i < list.size();i++){
if (list.get(i).getName().equals(line)){
System.out.println("Name:" + line);
System.out.println("Status:" + list.get(i).getStatus());
found = 1;
}
}
if (found == 0){
System.out.println("Not Found");
}
}
public void modifyMember(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter name:");
String line = sc.nextLine();
int found = 0;
for (int i = 0; i < list.size();i++){
if (list.get(i).getName().equals(line)){
System.out.println("Enter new name:");
line = sc.nextLine();
list.get(i).setName(line);
found = 1;
}
}
if (found == 0){
System.out.println("Not Found");
}
}
public void displayFriends(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter name:");
String line = sc.nextLine();
int found = 0;
for (int i = 0; i < list.size();i++){
if (list.get(i).getName().equals(line)){
list.get(i).displayFriends();
found = 1;
}
}
if (found == 0){
System.out.println("Not Found");
}
}
}
public class DemoSocial {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
UserDatabase db = new UserDatabase();
while(true){
System.out.println("1.Create a profile");
System.out.println("2.Leave the network");
System.out.println("3.Search Profile");
System.out.println("4.Modify Profile");
System.out.println("5.Display friends list");
System.out.println("6.Exit");
System.out.println("Enter choice:");
int n = Integer.parseInt(sc.nextLine());
if (n == 6)
break;
else if (n == 1)
db.addMember();
else if (n == 2)
db.removeMember();
else if (n == 3)
db.searchMember();
else if (n == 4)
db.modifyMember();
else if (n == 2)
db.displayFriends();
}
}
}