Workign on a Java Project, very similiar if you think about it like facebok or M
ID: 667163 • Letter: W
Question
Workign on a Java Project, very similiar if you think about it like facebok or Myspace but just a project.
Each person in the network should have a profile that contains: Name, Current status, and a list of friends
You should allow a person to join the network, leave the network, create a profile, modify their profile, search for other profiles, and add friends.
Please note that both the social network and the list of friends for each person are collections.
Here is what I have to offer as a structure:
import java.awt.image.*;
import java.util.ArrayList;
public class Driver
{
public static void main(String[] args)
{
System.out.println("Creating profiles and adding to database.");
Manager m = new Manager();
Profile john = new Profile();
john.setFirstName("John");
john.setLastName("Doe");
john.setStatus("My name is John.");
Profile jane = new Profile();
jane.setFirstName("Jane");
jane.setLastName("Doe");
jane.setStatus("My name is Jane.");
Profile billy = new Profile();
billy.setFirstName("Billy");
billy.setLastName("Bob");
billy.setStatus("My name is Billy Bob!");
m.addProfile(john);
m.addProfile(jane);
m.addProfile(billy);
m.display();
System.out.println("------------------------------------- ");
System.out.println("Creating friendships. ");
m.createFriendship(john, jane);
m.createFriendship(jane, billy);
m.display();
System.out.println("------------------------------------- ");
System.out.println("Removing John. ");
m.removeProfile(john);
m.display();
}
}
import java.awt.image.*;
import java.util.ArrayList;
public class Manager
{
ArrayList allProfiles;
public Manager()
{
allProfiles = new ArrayList ();
} // end default constructor
public void addProfile(Profile p)
{
allProfiles.add(p);
} // end addProfile
public void removeProfile(Profile p)
{
for (int x = 0; x < allProfiles.size(); x++)
{
allProfiles.get(x).removeFriend(p);
} // end for loop
allProfiles.remove(p);
} // end removeProfile
public void createFriendship(Profile a, Profile b)
{
a.addFriend(b);
b.addFriend(a);
} // end createFriendship
public void display()
{
for (int x = 0; x < allProfiles.size(); x++)
{
allProfiles.get(x).display();
System.out.println();
} // end for loop
} // end display;
}
import java.awt.image.*;
import java.util.ArrayList;
public class Profile
{
BufferedImage profilePicture;
String firstName, lastName;
String status;
ArrayList friends;
public Profile()
{
profilePicture = new BufferedImage(150, 150, BufferedImage.TYPE_INT_RGB);
firstName = "";
lastName = "";
status = "";
friends = new ArrayList ();
} // end default constructor
public BufferedImage getProfilePicture()
{
return profilePicture;
} // end getProfilePicture
public void setProfilePicture(BufferedImage b)
{
profilePicture = b;
} // end setProfilePicture
public String getName()
{
return firstName + " " + lastName;
} // end getName
public String getFirstName()
{
return firstName;
} // end getFirstName
public void setFirstName(String name)
{
firstName = name;
} // end setFirstName
public void setLastName(String name)
{
lastName = name;
} // end setLastName
public void setStatus(String stat)
{
status = stat;
} // end setStatus
public String getStatus()
{
return status;
} // end getStatus
public ArrayList getFriends()
{
return friends;
} // end getFriends
public void addFriend(Profile p)
{
if (!friends.contains(p))
friends.add(p);
} // end addFriend
public void removeFriend(Profile p)
{
friends.remove(p);
} // end removeFriend
public String toString()
{
return "Name: " + getName() + " Status: " + getStatus() + " Picture: " + getProfilePicture().toString().substring(0, 20) + " # of friends: " + friends.size() + " ";
} // end toString
public void display()
{
System.out.print(toString());
System.out.println("Friends:");
for (int x = 0; x < friends.size(); x++)
System.out.println(" " + friends.get(x).getName());
}
} // end Profile
Explanation / Answer
yes good ... creating profile and adding to database . but you can use exception to avoid error in the execution. you created entry form and adding friends and removing friends.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.