Question

The popular social network Facebook TM was founded by Mark Zuckerberg and his classmates at Harvard...

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.

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(extra credit), current status(Online, offline, busy,...), and a list of friends. Your application should allow a user to join the network, leave the network, create profile, modify the profile, search for other profiles, and add and remove friends.

use java

  • You need to implement CRUD (In computer programming, create, read, update, and delete (CRUD) are the four basic functions):
  • C= Create: Add profile- Add friends
  • R= Read: Read the information of a profile - Search for other profiles
  • U= Update: Update and edit the profile - Update the friend list
  • D= Delete: Delete a profile - Delete a friend of a profile.
  • You need to have a class diagram for your program (A simple one is acceptable):

Following are my projects. Could you help me add a class diagram for them? You can change the projects.

Profile class

import java.util.ArrayList;
import java.util.List;


public class Profile {


        public Profile(String name) {
                this.name=name;
                this.status="Online";
        }
        
        private String name;
        
        private String image;
        
        private String status;
        
        private List<Profile> friend=new ArrayList<Profile>();


        public String getName() {
                return name;
        }


        public void setName(String name) {
                this.name = name;
        }


        public String getImage() {
                return image;
        }


        public void setImage(String image) {
                this.image = image;
        }


        public String getStatus() {
                return status;
        }


        public void setStatus(String status) {
                this.status = status;
        }


        public List<Profile> getFriend() {
                return friend;
        }


        public void setFriend(List<Profile> friend) {
                this.friend = friend;
        }
        
        public void addFriend(Profile profile) {
                this.friend.add(profile);
        }


        @Override
        public String toString() {
                StringBuilder builder = new StringBuilder();
                builder.append("[name=");
                builder.append(name);
                builder.append(", image=");
                builder.append(image);
                builder.append(", status=");
                builder.append(status);
                builder.append(", friend=");
                builder.append(friend);
                builder.append("]");
                return builder.toString();
        }
        
}

Test.java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Test2 {


        private static List<Profile> profiles=new ArrayList<Profile>();


        public static void main(String[] args) {
                
                
                Scanner scanner=new Scanner(System.in);
                
                System.out.println("Please select option: ");
                System.out.println("1 for Add a new Profile ");
                System.out.println("2 for Search Profiles ");
                System.out.println("3 for Update and edit the profile ");
                System.out.println("4 for Delete a profile ");
                System.out.println("-1 for quit ");
                
                int iProfile=scanner.nextInt();
                
                if(iProfile==-1) {
                        scanner.close();
                        return;
                }else if(iProfile==1) {
                        System.out.println("Please enter name for profile :\n");
                        String name=scanner.next();
                        
                        if(name!=null && name.trim()!="") {
                                Profile profile=new Profile(name);
                                System.out.println("Please enter profile picture url :");
                                String profilePicture=scanner.next();
                                profile.setImage(profilePicture);
                                profiles.add(profile);
                        }
                        main(new String[] {});  
                        
                }else if(iProfile==2) {
                        System.out.println("Profile at this Network");
                        for(Profile profile: profiles) {
                                System.out.println(profile);
                        }
                        main(new String[] {});
                }else if(iProfile==3) {
                        System.out.println("Please select profile which you want to update: ");
                        for(int i=0; i<profiles.size(); i++) {
                                System.out.println(i+" for "+profiles.get(i));
                        }
                        System.out.println("-1 for return to main menu");
                        int uProfile=scanner.nextInt();
                        if(uProfile==-1) {
                                main(new String[] {});
                        }else {
                                Profile profile=profiles.get(uProfile);
                                System.out.println("select profile adding friend");
                                for(int i=0; i<profiles.size(); i++) {
                                        System.out.println(i+" for "+profiles.get(i));
                                }
                                System.out.println("-1 for return to main menu");
                                int fProfile=scanner.nextInt();
                                if(fProfile==-1) {
                                        main(new String[] {});
                                }else {
                                        profile.addFriend(profiles.get(fProfile));
                                        main(new String[] {});
                                }
                        }
                }else if(iProfile==4) {


                        System.out.println("Please select profile whose friend you want to delete");
                        for(int i=0; i<profiles.size(); i++) {
                                System.out.println(i+" for "+profiles.get(i));
                        }
                        System.out.println("-1 for return to main menu");
                        int dProfile=scanner.nextInt();
                        if(dProfile==-1) {
                                main(new String[] {});
                        }else {
                                System.out.println("select friend of "+profiles.get(dProfile).getName()+" want to delete");
                                for(int i=0; i<profiles.get(dProfile).getFriend().size(); i++) {
                                        System.out.println(i+" for "+profiles.get(dProfile).getFriend().get(i));
                                }
                                System.out.println("-1 for return to main menu");
                                int aProfile=scanner.nextInt();
                                if(aProfile==-1) {
                                        main(new String[] {});
                                }else {
                                        profiles.get(dProfile).getFriend().set(aProfile, null);
                                }
                        }
                }


        }


}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

using namespace std;

class person{

string name;

string image;

string current_status;

int total_friend;

int friends[20];

public:

person(){

name="";

image="";

current_status="";

total_friend=0;

}

person(string nam,string img,string status){

name=nam;

image=img;

current_status=status;

total_friend=0;

}

void set_name(string nam){

name=nam;

}

void set_image(string img){

name=img;

}

void set_status(string status){

current_status=status;

}

void add_friend(int p){

friends[total_friend++]=p;

}

string get_name(){

return name;

}

string get_image(){

return image;

}

string get_status(){

return current_status;

}

int no_friend(){

return total_friend;

}

};

int main(){

person p[100];

int count=0;

int choice;

int index,id;

string name,img,status;

do{

cout<<"1:join network\n2:create_profile\n3:update profile\n4:add friend\n5:leave network\n6:search for other\n7:quit\n";

cin>>choice;

switch(choice){

case 1:{cout<<"welcome to network!\n";

cout<<"your id is : "<<count<<"\n";

count++;

break;

}

case 2:{

cout<<"Enter your id : ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id \n";

break;

}

cout<<"Enter name : ";

cin>>name;

cout<<"Enter image file name : ";

cin>>img;

cout<<"Enter current_status : ";

cin>>status;

p[id]=person(name,img,status);

break;

}

case 3:{

cout<<"Enter your id : ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id \n";

break;

}

int another_choice;

do{

cout<<"1:change name\n2:change image\n3:change status\n4:quit";

cin>>another_choice;

switch(another_choice){

case 1:{

cout<<"Enter name : ";

cin>>name;

p[id].set_name(name);

break;

}

case 2:{

cout<<"Enter image file name : ";

cin>>img;

p[id].set_image(img);

break;}

case 3:{

cout<<"Enter current status : ";

cin>>status;

p[id].set_status(status);

break;}

}}while(another_choice!=4);

break;

}

case 4:{

cout<<"Enter your id : ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id \n";

break;

}

cout<<"enter id of friend : ";

int id2;

cin>>id2;

if(id2<0||id2>count){

cout<<"invalid id \n";

break;

}

p[id].add_friend(id2);

break;

}

case 5:{

cout<<"Enter your id : ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id \n";

break;

}

for(int i=id;i<count-1;i++)

p[i]=p[i+1];

count--;

break;

}

case 6:{

cout<<"Enter your id to be searched: ";

cin>>id;

if(id<0||id>count){

cout<<"invalid id \n";

break;

}

cout<<"\nname : "<<p[id].get_name();

cout<<"\nimage : "<<p[id].get_image();

cout<<"\ncurrent status : "<<p[id].get_status();

cout<<"\nnumber of friends : " <<p[id].no_friend();

cout<<"\n";

break;

}

case 7:{

cout<<"Thank You!\n";

break;

}

}

}while(choice!=7);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
The popular social network Facebook TM was founded by Mark Zuckerberg and his classmates at Harvard...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java program The popular social network Facebook ™ was founded by Mark Zuckerberg and his classmates...

    Java program The popular social network Facebook ™ was founded by Mark Zuckerberg and his classmates at Harvard University in 2004. At the time, he was a sophomore studying computer science. 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, optional image, current status, and a list of friends. Your application should allow a user to join the network, leave the...

  • Professionally and thoroughly comment on this code. //BinarySearchTree.java package Project.bst; //imports required import java.io.BufferedReader; import java.io.FileNotFoundException;...

    Professionally and thoroughly comment on this code. //BinarySearchTree.java package Project.bst; //imports required import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; class BSTTreeNode{    BSTTreeNode left, right;    String data; public BSTTreeNode(){    left = null;    right = null;    data = null; } public BSTTreeNode(String n){    left = null;    right = null;    data = n; } public void setLeft(BSTTreeNode n){    left = n; } public void setRight(BSTTreeNode n){   ...

  • I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String...

    I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String name, major, status; private int rank;    public Student() { this.name = this.major = this.status = ""; this.rank = 0; }    public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; } public String getName() { return name; } public String getMajor() { return major; } public String getStatus() { return status; }    public int...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

  • java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and sh...

    java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...

  • Need help debugging. Create an application that keeps track of the items that a wizard can...

    Need help debugging. Create an application that keeps track of the items that a wizard can carry. console application which has no errors: import java.util.Scanner; public class Console {        private static Scanner sc = new Scanner(System.in);     public static String getString(String prompt) {         System.out.print(prompt);         String s = sc.nextLine();         return s;     }     public static int getInt(String prompt) {         int i = 0;         boolean isValid = false;         while (!isValid) {             System.out.print(prompt);...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong?...

    I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong? Thanks ------------ package recipecollection; import java.util.ArrayList; public class SteppingStone5_RecipeTest { public static void main(String[] args) { ArrayList<String> recipeIngredients = new ArrayList<>(); recipeIngredients.add("Peanut butter"); recipeIngredients.add("Jelly"); recipeIngredients.add("Bread"); SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe("Peanut butter & jelly sandwich", 2, recipeIngredients, 300, 10.0); System.out.println("RECIPE 1"); recipe1.printRecipe(); System.out.println(); recipe1.setRecipeName("Turkey sandwich"); recipe1.setServings(5); recipe1.setTotalRecipeCalories(500); System.out.println(); System.out.println("RECIPE 1 (Modified)"); recipe1.printRecipe(); System.out.println(); System.out.println("RECIPE 2"); SteppingStone5_Recipe recipe2 = SteppingStone5_Recipe.createNewRecipe(); recipe2.printRecipe(); } } ///////////////// package recipecollection;...

  • (Reading & Writing Business Objects) I need to have my Classes be able to talk to...

    (Reading & Writing Business Objects) I need to have my Classes be able to talk to Files. How do I make it such that I can look in a File for an account number and I am able to pull up all the details? The file should be delimited by colons (":"). The Code for testing 'Select' that goes in main is: Account a1 = new Account(); a1.select(“90001”); a1.display(); Below is what it should look like for accounts 90000:3003:SAV:8855.90 &...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT