In this Assignment you will create a class that represents a Social Media profile (like a Facebook
Question:
In this Assignment you will create a class that represents a Social Media profile (like a Facebook profile many of you have). The name of this class will be SocialMediaProfile . There are many things we could represent about a Social Media Profile, we'll pick just a few to refresh our class writing skills. A SocialMediaProfile will have a name , an age, a country, a numberOfPosts, and numberOfLikes. Each of these will be private variables (these private variables must have the same exact names as the bolded names above) with the types int, double, or String (it's up to you to figure out which type for which private variable, not all types might be used). In addition to private variables you will have the following public methods
A constructor that will take in parameters to initialize the private variables in the order they were presented above. The constructor should ensure that anything with a number is not set to a value less than 0, if it is, then it initializes it to 0.
Getters and setters for each private variable must follow the naming convention used in the example Student class in Lecture 1 (i.e. for age we would have setage and getage ). The setters should ensure that the private variables are never set to an illogical value (i.e. if the client passes in a negative age to setage, age remains unchanged).
A member function, entitled averageLikesPerPost, that returns the average likes per post (divide numberOfLikes by number of posts). If there are no posts, simply return the value 0 (i.e. make a condition to ensure you do not divide by 0). This takes in no parameters but it does have a return value (you must determine the return type).
A toString method that overrides Object's toString, and prints out the person in the following format (the only spaces are after commas)
name:Bob, age:27, country:US, numberOfPosts:32, numberOfLikes:155. averageLikesPerPost:2.084
An equals method that overrides Object's equals. It should ensure that the Object being passed in is a SocialMediaProfile before casting it. Two Social Media Profiles are the same if all the private variables are equal. Remember to use .equals when comparing two Strings. You can use == to compare two ints.
Modern Database Management
ISBN: 978-0133544619
12th edition
Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi