Question

I am trying to create a simple property in a php file that displays information about...

I am trying to create a simple property in a php file that displays information about a dog. I can get the base code to work, but when I implement a new property It wont update. I've been staring at my code for hours now and can't figure out what i've done wrong. Again, the only function that I can't get working is the Gender Property

File Dog:

class Dog
{
// ----------------------------------------- Properties -----------------------------------------
private $dog_weight = 0;
private $dog_breed = "no breed";
private $dog_color = "no color";
private $dog_name = "no name";
private $dog_gender = "none";

// ---------------------------------- 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;
}
function set_dog_gender($value)
{
   $error_message = TRUE;
   (ctype_alpha($value) && strlen($value >= 4 && $value <=6)) ? $this->dog_gender = $value : $error_message = FALSE;
   return $error_message;
}

function get_properties()
{
   return "$this->dog_weight,$this->dog_breed,$this->dog_color,$this->dog_gender";
}
}
?>

File Lab:

require_once("dog.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
';
   $dog_error_message = $lab->set_dog_gender('Male');
       print $dog_error_message == TRUE ? 'Gender update successful
' : 'Gender update not successful
';
//-----------------------------Get Properties---------------------------
   $dog_properties = $lab->get_properties();
       list($dog_weight, $dog_breed, $dog_color, $dog_gender) = explode(',', $dog_properties);
       print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color. Dog Gender is $dog_gender";
?>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have rectified the problem and highlighted

<?php
class Dog
{
// ----------------------------------------- Properties -----------------------------------------
private $dog_weight = 0;
private $dog_breed = "no breed";
private $dog_color = "no color";
private $dog_name = "no name";
private $dog_gender = "none";
// ---------------------------------- 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;
}
function set_dog_gender($value)
{
$error_message = TRUE;
(ctype_alpha($value) && strlen($value) >= 4 && strlen($value) <=6) ? $this->dog_gender = $value : $error_message = FALSE;
return $error_message;
}
function get_properties()
{
return "$this->dog_weight,$this->dog_breed,$this->dog_color,$this->dog_gender";
}
}
?>
Output

Add a comment
Know the answer?
Add Answer to:
I am trying to create a simple property in a php file that displays information about...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am having a little trouble with my Python3 code today, I am not sure what...

    I am having a little trouble with my Python3 code today, I am not sure what I am doing wrong. Here are the instructions: and here is my code: update: I have seen I did not close x in sumFile and I am still only getting a 2/10 on the grader. any help appreciated. Lab-8 For today's lab you going to write six functions. Each function will perform reading and/or write to a file Note: In zybooks much like on...

  • To insure that file output is written to the disk you need to execute what method?...

    To insure that file output is written to the disk you need to execute what method? a. commit() b. write() c. close() d. complete() The following is called the ________ of a function. def myFunction(x,y) : a. header b. footer c. sentinel d. index True or False: A commonly used program that uses regular expressions is grep. True or False: In Python exception handling provides a mechanism for passing control from the point of the error detection to a handler...

  • Create a class called Flower. Add one member variables color. Add only one getter function for the color. The get function returns color. Implement a constructor that expects color value and assigns it to the member variable. Create a subclass of Flower

    Create a class called Flower. Add one member variables color. Add only one getter function for the color. The get function returns color. Implement a constructor that expects color value and assigns it to the member variable. Create a subclass of Flower named Rose. The Rose class has one member variable name.  Add a constructor which expects color and  name. Pass color to the base constructor and set name to it's member variable.Write a program that has an array of ...

  • Could someone help me out. I am not sure what I should be doing. Seeing it...

    Could someone help me out. I am not sure what I should be doing. Seeing it worked out will allow me to understand what I should be doing and then I can complete it on my own. Usando 2. Complete the Dog Class: a. Using the UML Class diagram to the right declare the instance variables. A text version is available: UML Class Diagram Text Version b. Create a constructor that incorporates the type, breed, and name variables (do not...

  • PHP - Use of classes This is a further development of the previous task, the participant...

    PHP - Use of classes This is a further development of the previous task, the participant registration. You must use the following Participant class. <?php class Deltaker { private $etterNavn; private $forNavn; private $fAar; function __construct(string $fornavn, string $etternavn, string $aar) { $this->forNavn = $fornavn; $this->etterNavn = $etternavn; $this->fAar = $aar; } function hentEtterNavn() : string { return $this->etterNavn; } function hentForNavn() : string { return $this->forNavn; } function hentFAar() : string{ return $this->fAar; } //Setters function settForNavn(string $fornavn) {...

  • c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any pa...

    c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. 3....

  • In Python and in one file please. (Simple functions with an expressions) Create a function called...

    In Python and in one file please. (Simple functions with an expressions) Create a function called load_inventory(filename). The filename argument in this case specifies the name of a file that contains all the inventory/product information for the store, including product names, descriptions, prices, and stock levels. This function should clear any information already in the product list (i.e., a fresh start) and then re-initialize the product list using the file specified by the filename argument. You can structure your file...

  • I am stuck with this coding problem from edx coding python 4.4.6: #This is a long...

    I am stuck with this coding problem from edx coding python 4.4.6: #This is a long one -- our answer is 20 lines of code, but #yours will probably be longer. That's because it's one of the #more authentic problems we've done so far. This is a real #problem you'll start to face if you want to start creating #useful programs. # #One of the reasons that filetypes work is that everyone #agrees how they are structured. A ".png" file,...

  • can you please follow all the instructions ? The answers that I got has either missing...

    can you please follow all the instructions ? The answers that I got has either missing range for loop or one funtion . Read the instructions carefully. At least 10% will be deducted if the instructions are not followed. For general lab requirements, see General Lab Requirements. Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input. Notes 1. Your program should use...

  • This program will store a roster of most popular videos with kittens. The roster can include...

    This program will store a roster of most popular videos with kittens. The roster can include at most 10 kittens.You will implement structures to handle kitten information. You will also use functions to manipulate the structure. (1) Create a structure kitten. The structure should contain the following attributes: name; string color; string score; integer Important! The name of the structure and each of its field must match exactly for the program to work and be graded correctly. (2) Create a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT