Question: PLEASE HELP, BELOW IS CODE WHERE THE REQUIRED VARIABLES AND METHODS ARE TO BE ADDED: public class SocialMediaProfile{ private String name; private int age; private

PLEASE HELP,

PLEASE HELP, BELOW IS CODE WHERE THE REQUIRED VARIABLES AND METHODS ARE

BELOW IS CODE WHERE THE REQUIRED VARIABLES AND METHODS ARE TO BE ADDED:

public class SocialMediaProfile{

private String name;

private int age;

private String country;

private int numberOfPosts;

private int numberOfLikes;

SocialMediaProfile(String _name, int _age, String _country, int noOfPosts, int noOfLikes){

name = _name;

if(_age

age = 0;

else

age = _age;

country = _country;

if(noOfLikes

numberOfLikes = 0;

else

numberOfLikes = noOfLikes;

if(noOfPosts

numberOfPosts = 0;

else

numberOfPosts = noOfPosts;

}

public void setname(String name) {

this.name = name;

}

public void setage(int age) {

if(age>0)

this.age = age;

}

public void setcountry(String country) {

this.country = country;

}

public void setnumberOfLikes(int numberOfLikes) {

if(numberOfLikes>0)

this.numberOfLikes = numberOfLikes;

}

public void setnumberOfPosts(int numberOfPosts) {

if(numberOfPosts>0)

this.numberOfPosts = numberOfPosts;

}

public String getname() {

return name;

}

public int getage() {

return age;

}

public String getcountry() {

return country;

}

public int getnumberOfPosts() {

return numberOfPosts;

}

public int getnumberOfLikes() {

return numberOfLikes;

}

public double averageLikesPerPost(){

if(numberOfPosts==0)

return 0;

return (double)numberOfLikesumberOfPosts;

}

public String toString() {

return "name:" + name + ", age:" + age + ", country:" + country + ", numberOfPosts:" + numberOfPosts + ", numberOfLikes:" + numberOfLikes + ", averageLikesPerPost:" + String.format("%.3f", averageLikesPerPost());

}

public boolean equals(SocialMediaProfile obj) {

return name.equals(obj.name) && age==obj.age && country.equals(obj.country) && numberOfPosts == obj.numberOfPosts && numberOfLikes == obj.numberOfLikes;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

SocialMediaProfile other = (SocialMediaProfile) obj;

if (age != other.age)

return false;

if (country == null) {

if (other.country != null)

return false;

} else if (!country.equals(other.country))

return false;

if (name == null) {

if (other.name != null)

return false;

} else if (!name.equals(other.name))

return false;

if (numberOfLikes != other.numberOfLikes)

return false;

if (numberOfPosts != other.numberOfPosts)

return false;

return true;

}

public static void main(String[] args){

{

}

SocialMediaProfile profile = new SocialMediaProfile("Ashok", 37, "US", 42, 122);

System.out.println(profile);

}

}

Remember to keep the names of variables and methods the same as I have them below for testing purposes!Remember to create your program piece by plece and test it in main before moving onto the noxt piece! Remember the Homework Help Forum if you need help! Task 1: Add the Required Variables Task 2: update the constructor to initialize these required variables. You should not need to pass in any additional parameters to the constructor We will now add the ability for a social media profile to have a friends List of other social media profiles (It will be more like following because Profile A can have Profile B as a friend but Profile B might not have Profile A as a friend) We will accomplish this through a Partially Filled Array which is an important concept. Basically A profile might start out with no friends and then it might add a friend which means the friendsList, which will be a SocialMedia Profile Array, will have 1 useful value and the rest not useful. So if the array is of length 10, it will have 1 useful value, and 9 trash values. To keep track of this we will have to have a count variable and to keep track of the total friends we can add to a profile we will have to have a MAX_FRIENDS variable Required Variables you will add 3 variables to Social Media Profile: friendsList, count, and MAX_FRIENDS, friendsList and count will be private and MAX_FRIENDS will be public. You will use your Social Media Profile you created in Assignment 1 and add a friendsList private variable which will be an array of all the Social Media Profiles that this person is following You will also add a count variable that keeps track of the number of friends and is also the next place we insert into the friendsList . Note that count will start at o when the SocialMedia Profile is constructed You will add a MAX_FRIENDS public static final variable that will be set to 3. For now we will assume each social media profile has at maximum 3 friends Your friendsList should be an array of SocialMedia Profiles that is constructed to be the length of MAX_FRIENDS in the constructor Task 3: Add the Required methods Making Sure to test each aspect of each method in main bofore moving onto the next one Required methods You should update your Social Media Profile code with the 2 following methods String string of Friends-> returns a string of the Social Media Profile person's name followed by the word friends and then each social Media Profile name who is a friend on the same line separted by a "." The format of this must be exact. For example let's say a profile with the name Ashok has friends withe the names Sandy and Julie and Trevor Calling stringOfFriends gives you the following string Ashok Friends: Sandy-Julie-Trevor You should implement this first because it'll be used to test all your functions (ie, you won't pass any tests unless this is working. To test it you can manually add students to the array Inside the constructor, just remember to comment this code out later when you actually do the addFriend function, boolean addFriend(?)-> Test 1: Adds a friend to the next array slot and updates the count variable and returns true Test 2: Duplicate Adds Only adds a friend If that friend hasn't already been added. If it is a duplicate being added this returns false Test 3. Additionally to Test 2, we only add a friend if we're not at capacity. If we are at capacity this returns false. Note we want to add a reference to the socialMedia Profile (Shallow Copy) so that if the two Social Media Profiles, Profile C and Profile B, reference the same friend, Profile A, in their friend's list and that Profilo A changes a value, that value change is reflected in the Profile C's and Profile B's Social Media Profiles Test 3: Returns the correct add friend returns true if the friend was successfully added Note If we were doing this for real want to update toString to Invoke stringOfFriends, update equals to consider the equality of two social Media Profiles taking into consideration the friendsList, and allow a profile to have more than 3 friends. We will deal with this later on

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!