Question

Java program

The popular social network Facebook ™ was founded by Mark Zuckerberg and his classmates at Harvard University in 2004. At the

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

ANSWER:

GIVEN THAT:

  

import java.io.*;
import java.util.*;

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();
                
           
       }       
   }
}

Add a comment
Know the answer?
Add Answer to:
Java program The popular social network Facebook ™ was founded by Mark Zuckerberg and his classmates...
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
  • It's important project. I need a help. Will give up vote for helping! Please use Java !!!!! Need ...

    It's important project. I need a help. Will give up vote for helping! Please use Java !!!!! Need clearly written java program code and sample output!!!!!! 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...

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
ADVERTISEMENT