Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PHP 7: Adjust Example 4-1 to include gender information from the Do It in Chapter 3. Use a text box to receive information from the

PHP 7:

Adjust Example 4-1 to include gender information from the Do It in Chapter 3. Use a text box to receive information from the user. Try to use HTML5 to restrict the type of information the user can enter in the text box. Test you code.

Example 4-1. Lab.html:

Dog Object

Dog Object Creater

Please complete ALL fields. Please note the required format of information.

Your Dog's Name (max 20 characters, alphabetic)

Your Dog's Breed (max 35 characters, alphabetic)

Your Dog's Color (max 15 characters, alphabetic)

Your Dog's Weight (numeric only)

Please complete ALL fields. Please note the required format of information.

Your Dog's Name (max 20 characters, alphabetic)

Your Dog's Breed (max 35 characters, alphabetic)

Your Dog's Color (max 15 characters, alphabetic)

Your Dog's Weight (numeric only)

Do It in Chapter 3:

Lab.php:

Require_once("e312dog.php");

$lab = new Dog('Fred','Lab','Yellow','100');

list($name_error, $breed_error, $color_error, $weight_error) = explode(',', $lab);

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

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

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

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

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

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

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

$dog_error_message = $lab->set_dog_weight('5');

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

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

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

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

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.";

?>

Dog.php:

class Dog

{

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

private $dog_weight = 0;

private $dog_breed = "no breed";

private $dog_color = "no color";

private $dog_name = "no name";

private $error_message = "??";

// ---------------------------------- Constructor ----------------------------------------------

function __construct($value1, $value2, $value3, $value4)

{

$name_error = $this->set_dog_name($value1) == TRUE ? 'TRUE,' : 'FALSE,';

$breed_error = $this->set_dog_breed($value2) == TRUE ? 'TRUE,' : 'FALSE,';

$color_error = $this->set_dog_color($value3) == TRUE ? 'TRUE,' : 'FALSE,';

$weight_error= $this->set_dog_weight($value4) == TRUE ? 'TRUE' : 'FALSE';

$this->error_message = $name_error . $breed_error . $color_error . $weight_error;

}

//------------------------------------toString--------------------------------------------------

public function __toString()

{

return $this->error_message;

}

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

function set_dog_name($value)

{

$error_message = TRUE;

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

return $this->error_message;

}

function set_dog_weight($value)

{

$error_message = TRUE;

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

return $this->error_message;

}

function set_dog_breed($value)

{

$error_message = TRUE;

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

return $this->error_message;

}

function set_dog_color($value)

{

$error_message = TRUE;

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

return $this->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.";

}

}

?>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

ISBN: 3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

6. Knowledge management.

Answered: 1 week ago