Question: Revised Yet Again Week 12 Week 12 Assignment 2 (Part 2): On 10/16/2017, we discussed and demonstrated the Facebook example. PPT slides about this example

Revised Yet Again Week 12

Week 12 Assignment 2 (Part 2):

On 10/16/2017, we discussed and demonstrated the Facebook example. PPT slides about this example and source code can be found on the class website.

In that example, the testFacebook class uses an array to store the FacebookPersons. The number of FacebookPersons that can be created is limited by the size of the array. Your homework is to write another test class named testFacebook_ArrayList that uses ArrayList instead of array to store FacebookPersons. With this new test class, now you can create any number of FacebookPersons.

When your program runs, you will be asked to enter the name for a person to be created. Once you enter a name, a FacebookPerson is created and a window is shown (just like in the Facebook example). If you enter a name that already exists, your program should print a Name already exist. Try again! message and asks the user enter another name. After all the persons have been created, you enter #### to end the creation of FacebookPersons. Then the program will ask you to select a person and type the mood. Just like in the Facebook example, when the selected person does not exist, the program prints an unrecognized name message; when the mood changes to happy, the corresponding window is displayed with a red background; when you enter ####, the program is terminated.

Write the testFacebook_ArrayList class. Do not change the other files. Turn in only the testFacebook_ArrayList.java file. Below is an illustration of how the program runs. Your code must produce the output below AND use an ArrayList instead of an array to store FacebookPersons.

Sample Output:

Revised Yet Again Week 12 Week 12 Assignment 2 (Part 2): On

Testfacebook java example

package Facebook;

import java.util.*;

public class testFacebook{

public static void main (String[] args){

// Prompt user to enter the number of facebookpresons Scanner userInput = new Scanner(System.in); System.out.println("Enter the number of facebookpresons to be created: "); int numP=0; while(true){ try{ String inputString = userInput.nextLine(); numP = Integer.parseInt(inputString); if(numP>0 && numP

FacebookPerson[] fbp = new FacebookPerson[numP];

//Ask the user to enter the name for each person, and create the persons for(int i=0; i

//Ask the user to set the mood for a person, and update the mood, enter "####" to exit while(true){ System.out.println("Enter the name for a person (enter #### to exit):"); String name = userInput.nextLine(); if(name.equals("####")) System.exit(0); int personID = -1; for(int i=0; i

} // end main

}

create a person with name (enter #### to end the creation of FacebookPersons): John FacebookPerson John is created! create a person with name (enter #### to end the creation of FacebookPersons): John Name already exist. Try again! Create a person with name (enter #### to end the creation of FacebookPersons): Alex FacebookPerson Alex is created! Create a person with name (enter #### to end the creation of FacebookPersons): select a person and type the mood below Enter the name for a person (enter #### to exit): Alex Enter the mood for the person: happy Enter the name for a person (enter #### to exit): Mike unrecognized name! Enter the name for a person (enter #### to exit)

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!