Question: Complete the Person class: For setEmail, setFirstName, and setSurname: if the method is passed an empty string, it should do nothing; but otherwise it should

Complete the Person class:

For setEmail, setFirstName, and setSurname: if the method is passed an empty string, it should do nothing; but otherwise it should set the appropriate field.

For setMobile: if the method is passed a valid mobile phone number, it should set the appropriate field; otherwise it should do nothing. A string is a valid mobile phone number if every character in it is a digit from 0 to 9.

Hints:

To convert a string so you can process it in a for-each loop you can use the String.toCharArray method. You do not need to know any array operations for this task.

To test whether a character is a digit, you can use the Character.isDigit method.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Complete the printContactDetails method:

The method should print, in order, 3 lines showing the name, mobile and email of the person, prefaced by the strings "name: ", "mobile: " and "email: ", respectively. The name of a person is their first name and surname, separated by a space.

For each of the social media accounts the person has, the method should print one line containing the website name, the userID, and the website URL, separated by commas.

For example, the following code will construct a Person object, and add details to it:

Person p = new Person("Diana", "Prince");

p.setMobile("0409670123");

p.setEmail("diana.prince@inscom.mil");

p.addSocialMediaAccount("@dianap", "Twitter", "http://twitter.com/", 50);

p.addSocialMediaAccount("diana.prince", "Facebook", "http://facebook.com/", 90);

Calling the printContactDetails method on the object p should print the following:

name: Diana Prince

mobile: 0409670123

email: diana.prince@inscom.mil

Twitter,@dianap,http://twitter.com/

Facebook,diana.prince,http://facebook.com/

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.util.ArrayList; /** * Person details including contacts and social media accounts * */ public class Person { private String firstName; private String surname; private String mobile; private String email; private ArrayList socialMediaAccounts; /** * Create a Person with the first name and surname given by * the parameters. */ public Person(String firstName, String surname) { this.firstName = firstName; this.surname = surname; mobile = null; email = null; this.socialMediaAccounts = new ArrayList(); }

/** * @return the person's first name */ public String getFirstName() { return ""; // replace this line with your own code } /** * Set the person's first name * unless the parameter is an empty string. */ public void setFirstName(String firstName) { // replace this line with your own code } /** * Return the person's surname */ public String getSurname() { return ""; // replace this line with your own code } /** * Set the person's surname * unless the parameter is an empty string. */ public void setSurname(String surname) { // replace this line with your own code } /** * Return the person's mobile phone number */ public String getMobile() { return ""; // replace this line with your own code } /** * Set the person's mobile phone number */ public void setMobile(String mobile) { this.mobile = mobile; } /** * Return the person's email address */ public String getEmail() { return ""; // replace this line with your own code } /** * Set the person's email address */ public void setEmail(String email) { // replace this line with your own code } /** * Create a new SocialMediaAccount object, and add it to the socialMediaAccounts list. */ public void addSocialMediaAccount(String userID, String websiteName, String websiteURL, int activityLevel) { // replace this line with your own code } /** * Search the socialMediaAccounts list for an account on the website specified by the websiteName * parameter, and return the userID for that account. If no such account can be found, return * null. */ public String getSocialMediaID(String websiteName) { return ""; // replace this line with your own code }

/** Print the person's contact details in the format given in the * project specifications. */ public void printContactDetails() { // replace this line with your own code }

}

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!