Question: PHP 7: In addition to creating an additional property ($dog_gender) and set method in the Dog class, create method to display the updated values. Also

PHP 7:

In addition to creating an additional property ($dog_gender) and set method in the Dog class, create method to display the updated values. Also update the lab.php file to include a print statement (similar to the examples in this section) to call the get methods.

Dog.php:

class Dog

{

// ----------------------------------------- Properties -----------------------------------------

private $dog_weight = 0;

private $dog_breed = "no breed";

private $dog_color = "no color";

private $dog_name = "no name";

// ---------------------------------- Set Methods ----------------------------------------------

function set_dog_name($value)

{

$error_message = TRUE;

(ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $error_message = FALSE;

return $error_message;

}

function set_dog_weight($value)

{

$error_message = TRUE;

(ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $error_message = FALSE;

return $error_message;

}

function set_dog_breed($value)

{

$error_message = TRUE;

(ctype_alpha($value) && strlen($value) <= 35) ? $this->dog_breed = $value : $error_message = FALSE;

return $error_message;

}

function set_dog_color($value)

{

$error_message = TRUE;

(ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $error_message = FALSE;

return $error_message;

}

// ----------------------------------------- Get Methods ------------------------------------------------------------

function get_dog_name()

{

return $this->dog_name;

}

function get_dog_weight()

{

return $this->dog_weight;

}

function get_dog_breed()

{

return $this->dog_breed;

}

function get_dog_color()

{

return $this->dog_color;

}

function get_properties()

{

return "$this->dog_weight,$this->dog_breed,$this->dog_color.";

}

}

?>

Do it. Page 101.

Require_once("e310dog.php");

$lab = new Dog;

// ------------------------------Set Properties--------------------------

$dog_error_message = $lab->set_dog_name('Fred');

print $dog_error_message == TRUE ? 'Name update successful
' : 'Name update not successful
';

$dog_error_message = $lab->set_dog_weight(50);

print $dog_error_message == TRUE ? 'Weight update successful
' : 'Weight update not successful
';

$dog_error_message = $lab->set_dog_breed('Lab');

print $dog_error_message == TRUE ? 'Breed update successful
' : 'Breed update not successful
';

$dog_error_message = $lab->set_dog_color('Yellow');

print $dog_error_message == TRUE ? 'Color update successful
' : 'Color update not successful
';

// ------------------------------Get Properties--------------------------

print $lab->get_dog_name() . "
";

print $lab->get_dog_weight() . "
";

print $lab->get_dog_breed() . "
";

print $lab->get_dog_color() . "
";

$dog_properties = $lab->get_properties();

list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties);

print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color.";

?>

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!