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 creating an Android application that has a login/registration page. To be able to use...

    I am creating an Android application that has a login/registration page. To be able to use the application, the user must be 21 + years old. I have previously created php files for login, register, and update user info. I am having trouble on where to add code that will check if the user is 21+ into the update_user_info.php file I have created. I have figured out the correct mysql command to add to the php file, I am just...

  • 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 am trying to write a c++ program that will add two binary numbers that are...

    I am trying to write a c++ program that will add two binary numbers that are entered into the command line. I cannot get the program to send anything to stdout. code attached. int main(int argc, char *argv[]) //           IN       IN {    char partialSum[MAX_DIGITS + 1]; //partial sum of the binary numbers    char sum[MAX_DIGITS + 1];       //sum of the binary numbers    bool noError;       //no error flag       //Exit if insufficient arguments...

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

  • Inheritance and Polymorphism (use Pet.java) You are given a class named Pet.java.   Create two child classes...

    Inheritance and Polymorphism (use Pet.java) You are given a class named Pet.java.   Create two child classes named Cat.java and Dog.java. Cat.java should add attributes for color and breed. Dog.java should add attributes for breed and size (use String for small, medium, large). Add appropriate constructors, getter/setter methods and toString() methods.   In a separate file named PetDriver.java, create a main. In the main, create an ArrayList of Pet. Add an instance of Cat and an instance of Dog to the ArrayList....

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

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