Question: Need help with this question. Step 0. Draw a UML class diagram of the MiniFacebookAccount class.Follow the format of Figure 3 - 6 in the

Need help with this question.

Step 0. Draw a UML class diagram of the MiniFacebookAccount class.Follow the format of Figure 3 - 6 in the UML Class Diagram tutorial (from this unit). Pay attention to visibility type, type of a param/data member/return type of a method, and how an item should be listed in a class diagram. Put this class diagram in your HW report document.

Step 1. (MiniFacebookAccount class) Change the boolean exists(String friendName) method to have an int return type.Modify the code to return index of the matching string if the parameter string is found, otherwise return -1.

Step 2. (MiniFacebookAccount class) modify the addFriend method so it works with the modified exists method.Compile and verify that your program still works. The program should generate this output:

Account of Student Name: cannot add Tracy Smith. Already on the list.

Account of Student Name: cannot add Samuel Ebeling. Friend list is full.

==========================

Account name: Student Name

Friends with:

Mary Brown

Tracy Smith

Muhammad Ali

Richard Young

Ben Johnson

==========================

Step 3. (Driver class)

Change the account owner "Student Name" to your own name.

Add code to the end of main():

print 3 blank lines

createanother object of MiniFacebookAccount with account name "Snow White".

Call addFriend method to add the following friends in the specified order: Happy, Doc, Grumpy, Sleepy, Dopey, Bashful, and Sneezy.

CallprintAccount().

Include a screenshot of your program output from this step (#1, should show your name for the first account) in your HW document:

Account of Student Name: cannot add Tracy Smith. Already on the list.

Account of Student Name: cannot add Samuel Ebeling. Friend list is full.

==========================

Account name: Student Name

Friends with:

Mary Brown

Tracy Smith

Muhammad Ali

Richard Young

Ben Johnson

==========================

Account of Snow White: cannot add Bashful. Friend list is full.

Account of Snow White: cannot add Sneezy. Friend list is full.

==========================

Account name: Snow White

Friends with:

Happy

Doc

Grumpy

Sleepy

Dopey

==========================

Step 4. (MiniFacebookAccount class) Add a public method removeFriend(String friendName)with boolean return type.This would be handy if you need to unfriend someone.J

If list is empty

Print to report empty list

return false.

else if friendName not exists in the list

Print to report remove failed as friendName is not a friend.

Return false

else // is a friend. Remove from list

xxx

return true

End if

Remove version 1: implement the removing first using System.arraycopy().Research how to use it if needed.After it works, comment this version out (leave it in the code for grading).

Remove version 2: next accomplish the same task by shifting elements in a loop.You may want to review lecture from last unit.

You may add additional code to Driver to test your remove method.

Step 5. (MiniFacebookAccount class) Revise addFriend method again so that it adds a friend to the list while maintaining the list in alphabetic order.Your method should still print an error message if the list is already full or if a friend is already on the list.

If (friend list is full)

Report full list

else if (duplicate friend name)

Report duplicate

else // okay to add

// add the friend name into

// the array such that the names are always

// in alphabetic order - yeah, insert

End if

You may want to review insertion code from last unit (insertion code, not insertion sort code!)

Be sure to use the compareTo() or compareToIgnoreCase() method of String class to compare two strings for their alphabetic order (see ch5.6 and Java API documentation). ==, <, and > don't work here.

After completing this step include a screenshot of your program output (#2, should show your name for the first account. May have additional prints from code testing remove) in the HW report document:

Account of Student Name: cannot add Tracy Smith. Already on the list.

Account of Student Name: cannot add Samuel Ebeling. Friend list is full.

==========================

Account name: Student Name

Friends with:

Ben Johnson

Mary Brown

Muhammad Ali

Richard Young

Tracy Smith

==========================

Account of Snow White: cannot add Bashful. Friend list is full.

Account of Snow White: cannot add Sneezy. Friend list is full.

==========================

Account name: Snow White

Friends with:

Doc

Dopey

Grumpy

Happy

Sleepy

==========================

(Extra Credit) Step 6. (MiniFacebookAccount class) Revise your MiniFacebookAccount class so it will "grow" automatically when the internal array is full.

The addFriend method should now work like this:

If (duplicate friend name)

Report duplicate

Else

if (friend list is full)

// "grow" internal array

Createa new String array with 2 * friendList.length spots

Copy items from friend list to this new array

Let friend list point to this new array

End if

// now okay to add

// add the friend name into

// the array such that the names are always

// in alphabetic order

End if

You may use a Java API method or writeyour own loop.For the purpose of this project, do not worry about whether the new capacity will be too big for the int data type.

After completing this step include a screenshot of your program output (#3. Extra credit only. Should show your name for the first account. May have additional prints from code testing remove) in the report document.

Congratulations you just build an ArrayList kind of class!

In case you wondered, the print statements in add/remove are included for debugging. Such prints should not be included in production systems. Exceptional conditions should be handled by proper return value and/or exception handling.

Overall comment your program appropriately.Pay attention to standard stuff like coding style, indention, heading, and curly braces.Double check your code for indentation and alignment after you paste it in your document.

Submission: one word/PDF document + three .java files

  • Assignment document:
  • Exercise 1: screenshot of running program
  • Exercise 2: answers
  • Project: UML class diagram; screenshots of running program
  • Exercise 1: StudentRecordManager.java
  • Project: Driver.java and MiniFacebookAccount.java
  • Use the assignment rubric to check the completeness of your work before turning it in.

/**

* MiniFacebookAccount.java (partial code)

* (add code at the 5 places labeled with ADD)

*

* CS219. Array as instance data member practice

* A simple class to hold account name and a list of friends

*/

public class MiniFacebookAccount

{

// Constant to specify default maximum number of friends allowed

// only used when creating initial array obj

private static final int DEFAULT_CAPACITY = 5;

// Name of account holder

private String name;

// List of friends (just names)

private String[] friendList;

// track number of friends actually have

private int numFriends;

//-----------------------------------------------

// 1-param constructor. Creates a MiniFacebookAccount

// object for a user with specified name

public MiniFacebookAccount(String name)

{

this.name = name;

// numFriends has default value 0

// ADD #1: initialize instance data member friendList to

//a new String array of DEFAULT_CAPACITY spots

} // end 1-param constructor

//-----------------------------------------------

// Adds the specified friend

/*

* The name will be appended to the end of the friend list and

* numFriends increased by one if the friend list is not full

* and the name is not already in the list. Otherwise displays

* error messages and no actions taken.

*/

public void addFriend(String friendName)

{

if (numFriends >= friendList.length) // full

{

System.out.println("Account of " + name + ": cannot add " + friendName + ". Friend list is full.");

}

// !!! Scroll down to completeADD #2 first

// ADD #3: replace the word false with code to call method exists to check

//if a friend is already added

else if (false) // duplicate

{

System.out.println("Account of " + name + ": cannot add " + friendName + ". Already on the list.");

}

else // add to friend list

{

// ADD #4: replace the fake print below with code to add a friend

// for example, if there are currently 2 friends (numFriends

// is 2, spot [0] and [1] already filled), friendName should

// be added to spot 2 [2] and numFriends incremented by 1

// (becomes 3)

System.out.println("-- fake print for add " + friendName);

}

} // end addFriend

// Prints accout user name and list of friends on screen

public void printAccount()

{

// print heading

System.out.println(" =========================="); // leading separator line

System.out.println("Account name: " + name);

System.out.println("Friends with: ");

// print account name and friends

// ADD #5: replace the fake print below with code to print all friends

System.out.println("-- fake print for print friends.");

} // end printAccount

//------------------------------------------------

// Tests if the specified name already exists in the list

private boolean exists(String friendName)

{

if (numFriends == 0) // empty list

return false;

// ADD #2: search through the list (linear search): index 0 to numFriends-1

//return true if name exists.

// Reminder: ==, <, > don't work if we want to compare contents of strings

// END ADD #2

return false;// not found

} // end exists

} // end class MiniFacebookAccount

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 Programming Questions!