Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Freshmen Conputer Science. Topics: Writing Object Classes 1. Create a class, Eac

ID: 3906918 • Letter: F

Question

Freshmen Conputer Science. Topics: Writing Object Classes 1. Create a class, EacabookStatus, .that represents a Facebook status. The class will have the following attributes: . status - the status nrof.ikes- the number of times this status has been liked. publis EacebookStatus (String status) I sets the status, and initializes In addition, the class should have two constuctors: to 0. status and nrOflikes to the specified parameters. The class will also have the following methods: ewbus string tostring() " That creates and returns a string representation of the class. You chose the format. · 2. Now, create another class EacebookUser that represents a Facebook user. This class the first name. lastName- the last name of the user the username of the user . statuses- an array of Facebook statuses posted by the user The following constructor: String username) II That sets all the attributes to the values of the parameters. The array of statuses is set to an empty array. . pubiic String sestrina ) Creates and returns a String representation of the user including all the statues. pubLis void add (Eassbeaksasua tostatua) I/A method that adds a fbStatus to the array of statuses. To accomplish this you will create a new array that is the size of the current array plus 1 and then copy all the elements of the original array of statuses, and then insert the element (bStatus) at the end, and finally assign the new array to the attribute statuses. . A main method that: o creates a facebook user. o creates at least 5 facebook statuses. o prints the facebook user. o adds them to the user. o prints the user. For the main method you do not have to read input from the user, you can just hardcode the values.

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you


FacebookStatus.java
========

public class FacebookStatus {
private String status;
private int nrOfLikes;

public FacebookStatus(String status){
this.status = status;
this.nrOfLikes = 0;
}

public FacebookStatus(String status, int nrOfLikes){
this.status = status;
this.nrOfLikes = nrOfLikes;
}

public String toString(){
return "Status: " + status + "[No. of likes: " + nrOfLikes + "]";
}
}


FacebookUser.java
======
public class FacebookUser {
private String firstName;
private String lastName;
private String userName;
private FacebookStatus[] statuses;

public FacebookUser(String fname, String lname, String uname){
firstName = fname;
lastName = lname;
userName = uname;
}

public String toString(){
String s = "Name: " + lastName +", " + firstName + ", Username: " + userName +" ";
if(statuses != null)
{
for(int i = 0; i < statuses.length; i++)
{
s += statuses[i] + " ";
}
}
return s;
}

public void add(FacebookStatus fbStatus){
if(statuses == null)
statuses = new FacebookStatus[1];

else{
FacebookStatus[] temp = new FacebookStatus[statuses.length + 1];
for(int i = 0; i < statuses.length; i++)
temp[i] = statuses[i];

statuses = temp;
}

int len = statuses.length;
statuses[len-1] = fbStatus;
}


}


FacebookApplication.java
---------

public class FacebookApplication {
public static void main(String[] args) {
FacebookUser user = new FacebookUser("Jonn", "Smith", "jsmith");

System.out.println("Before adding the status, the user is " + user);

FacebookStatus s1 = new FacebookStatus(" I'm not lazy, I'm on energy saving mode :D", 10);
FacebookStatus s2 = new FacebookStatus("Not always 'Available' try your luck!");
FacebookStatus s3 = new FacebookStatus("Sometimes you succeed... and other times you learn.", 20);
FacebookStatus s4 = new FacebookStatus("Behind every successful man is a surprised woman", 5);
FacebookStatus s5 = new FacebookStatus("Silent people have the loudest minds.");
user.add(s1);
user.add(s2);
user.add(s3);
user.add(s4);
user.add(s5);


System.out.println("After adding the status, the user is " + user);

}
}

output
----
Before adding the status, the user is
Name: Smith, Jonn, Username: jsmith

After adding the status, the user is
Name: Smith, Jonn, Username: jsmith
Status: I'm not lazy, I'm on energy saving mode :D[No. of likes: 10]
Status: Not always 'Available' try your luck![No. of likes: 0]
Status: Sometimes you succeed... and other times you learn.[No. of likes: 20]
Status: Behind every successful man is a surprised woman[No. of likes: 5]
Status: Silent people have the loudest minds.[No. of likes: 0]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote