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
  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • 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) {...

  • 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...

  • WRITE IN JAVA: I've been trying to do this for hours and I can't figure this...

    WRITE IN JAVA: I've been trying to do this for hours and I can't figure this out. I tried the toArray method and I'm stumped. I'm not sure if the remove method is right aswell. If you need anymore info, let me know. I need the following methods completed: toArray Remove ReverseArray /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template...

  • I need this in java please Create an automobile class that will be used by a...

    I need this in java please Create an automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class: private string make private string model private string color private int year private int mileage. Your program should have appropriate methods such as: default constructor parameterized constructor add a new vehicle method list vehicle information (return string array) remove a vehicle method update vehicle attributes method. All methods...

  • 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 ...

  • I wrote code in C++ that takes a text file containing information on different football players...

    I wrote code in C++ that takes a text file containing information on different football players and their combine results, stores those players as a vector of objects of the class, and prints out those objects. Finally, I wrote a function that calculates the average weight of the players. MAIN.CPP: #include "Combine.h" #include using namespace std; // main is a global function // main is a global function int main() { // This is a line comment //cout << "Hello,...

  • 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...

  • 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....

  • 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...

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