php test3

Home > Preview

The flashcards below were created by user slc53 on FreezingBlue Flashcards.


  1. A public property can be
    directly accessed by code outside of the class.
  2. Private properties
    cannot be directly accessed by code outside the class.
  3. Protected properties can
    only be accessed within the class itself and its inherited classes.
  4. By default, properties are
    • public.
    • Style dictates that you provide the access modifier. In other words, start each property with either private, protected or public.
  5. $this
    Within a class, variable $this is used to refer to the current object. It allows you to access the properties and methods of the current object. The object access operator (->) is used to provide the access
  6. clsVehicle has Model, Price, MarkUpPercent, TaxRate
    Write the class definition to private
    • <?php
    • class clsVehicle
    • {  private $Model;
    •     private $Price;
    •     private $MarkUpPercent;
    •     private $TaxRate;
  7. clsVehicle has Model, Price, MarkUpPercent, TaxRate. Write the constructor passing Model and Price.
    • public function __construct(
    •         $pModel="VehModel", $pPrice=1000)
    • {   $this->setModel($pModel);
    •      $this->setPrice($pPrice);      
    •      $this->setMarkUpPercent();
    •      $this->setTaxRate();
    •     }
  8. Write the destructor for clsVehicle.
    • public function __destruct()
    • {
    •         //ex close connection to     
    • }
  9. Write the getModel.
    • public function getModel()
    • {
    •         return ($this->Model);    
    • }
  10. write the function to set the model
    • public function setModel($pModel)    
    • {   if ($pModel != NULL)
    •             $this->Model = $pModel;    
    • }
  11. An abstract class is
    a class that cannot be used to create an object.
  12. A concrete class is
    a class that can be used to create an object.
  13. Making a function abstract in a parent class
    forces the child class to implement the method.
  14. public vs protected vs private
    If you need the user of the class (UsingAllVehicles) to have access to it, it has to be public. If you need the child of the class (clsTransport or clsSchoolBus) to have access to a function in the parent class, make it protected. If it is only needed in the current class, make it private.
  15. when do you code abstract
    in parent class definition but not child class
  16. An abstract method is
    a method that is declared (prototyped) in the parent class and coded in the child classes. Making a function abstract in a parent class forces the child class to implement the method.
  17. data members of parent vehicle
    • abstract class clsVehicle
    • {   private $Model;
    •     private $Price;
    •     private $MarkupPercent;
    •     private $TaxRate;
  18. constructor for vehicle with default values
    • abstract class clsVehicle
    • {
    • protected function __construct
    •      ($pModel="", $pPrice=0,
    •      $pMarkupPercent=0.45,
    •      $pTaxRate=0.13)
    • {       $this->setModel($pModel);
    •        $this->setPrice($pPrice);
    •  $this->setMarkupPercent($pMarkupPercent);
    •        $this->setTaxRate($pTaxRate);
    • }
  19. get model for vehicle parent
    • public function getModel()
    • {
    •         return $this->Model;    
    • }
  20. set model for vehicle parent
    • public function setModel($pModel)
    • {        If ($pModel!= NULL)
    •                $this->Model = $pModel;    
    • }
  21. code CalculateMarkup
    • private function CalculateMarkup ()    
    • {  
    • return($this->Price*$this->MarkupPercent); 
    • }
    • // This function is private. It is only being called from this class.
  22. $KCBus is a clsSchoolBus
    $KCBus->CalculateMarkup() works when
    • public
    • public function CalculateMarkup ()
    • error when private or protected
  23. create HCBus object
    $HCBus =  new clsSchoolBus ();
  24. how to set the number of students on bus to 15
    $HCBus->setnumStudents(15);
  25. how to get the number of students on bus
    echo $HCBus->getnumStudents();
  26. $HCBus =  new clsSchoolBus ();
    echo $HCBus->getMarkupPercent();
    displays
    0.45, the default value
  27. clsSchoolBus is a clsVehicle
    clsSchoolBus has attribute
    numStudents
    what is cls definition
    • class clsSchoolBus extends clsVehicle
    • {
    •     private $numStudents;
  28. clsSchoolBus is a clsVehiclecls
    SchoolBus has attribute numStudents.
    Write constructor
    • public function __construct
    •    ($pNumStudents=0, $pModel="",
    •    $pPrice=0, $pMarkupPercent=0.45,
    •    $pTaxRate=0.13)    
    • {
    •      $this->setnumStudents($pNumStudents);
    • // call vehicle constructor to finish the initialization       parent::__construct($pModel, $pPrice,
    •    $pMarkupPercent, $pTaxRate);    
    • }
  29. private function CalculateMarkup ()
    public function CalculateTotal (&$pMarkup, &$pSubtotal, &$pTaxAmount, &$pTotal)
    $BigRig = new clsTransport (55, "XXL", 550000, 0.35, 0.13);
    How do you display BigRig markup?
    • $BigRig->CalculateTotal ($Markup,
    •       $Subtotal, $TaxAmount, $Total);
    • echo "<p>Markup: " .
    •      number_format($Markup);
  30. securityCheck(); is different for the different subclasses. How is it coded?
    • abstract class clsVehicle
    • {
    •    abstract public function securityCheck();
    • ...
    • class clsSchoolBus extends clsVehicle
    • {
    •    public function securityCheck()
    •   {         
    •      return ("Purchaser is cleared to
    •            drive kids");
    •    }
    • ...
  31. how to require a file
    • <?php
    •   require_once ("clsVehicle-m.php");
  32. clsPerson with first and name attributes
    definition
    abstract class clsPerson {    private $firstName;    private $lastName;
  33. constructor for clsPerson
    • protected function __construct
    •      ($pfirstName = "", $plastName = "")
    • {
    •    $this->setFirstName($pfirstName);
    •    $this->setLastName($plastName);
    • }
  34. bdayGreeting is different for the different subclasses
    • abstract class clsPerson {
    •    abstract public function bdayGreeting();
    •    ...
    • class clsCustomer extends clsPerson {
    •    public function bdayGreeting()
    • {        echo " Happy Birthday to our fav customer " . $this->getFirstName()        . " " . $this->getLastName() . "Come in for 10% off.";   
    • }
  35. clsCustomer with creditcard
    • class clsCustomer extends clsPerson
    • {
    •     private $creditCardNumber;
    •     public function __construct
    •     ($pfirstName = "", $plastName = "",
    •       $pCardNumber = "")
    •     {
    •         $this->setCardNumber
    •                    ($pCardNumber);
    •         parent::__construct($pfirstName,
    •               $plastName);
    •     }
  36. create customer object passing first, last and cc#
    $cust = new clsCustomer("Mini", "Me", "123-456-789");
  37. // set the time zone
    date_default_timezone_set('America/Toronto');  // set the time zone
  38. / get server date
    $now = new DateTime();     // get server date
  39. create an object with a specific time
    $expires = new DateTime ('2020-04-30 15:25:00');
  40. tomorrow
    $tomorrow = new DateTime ('+1 day');
  41. in 3 weeks
    $dueDate = new DateTime ('+3 weeks');
  42. one week from friday at 14:25
    $appointment = new DateTime ('+next Friday +1 week 14:25');
  43. How to display todays date.
    • $today = new DateTime();
    • echo "Today's Date :" . $today->format('M j, Y') . ".";
  44. //Assign a due date 3 weeks from now
    • $checkoutLength = new DateInterval('P3W');
    • $dueDate = new DateTime();
    • $dueDate->add($checkoutLength);
  45. how to assign a datetime
    $dob = new DateTime('1967-03-24 02:02:02');
  46. how to set an interval
    $someInterval = new DateInterval ('P3Y05M06DT17H02M08S');
  47. Assignments late or on time?
    • $due = new DateTime('2016-07-04 9:30:00');
    • $submitted = new DateTime('2016-07-15 10:33:22');
    • $daysLate = $submitted->diff($due);
    • // this is a DateInterval
  48. add($interval)
    sub($interval)
    diff($date)
    add($interval): add an amount of time specified by the DateInterval object.

    sub($interval): subtract the amount of time specified by the DateInterval object.

    diff($date): return a date interval object that represents the amount of time between two dates. Return a positive or negative number.
  49. $daysLate = $submitted->diff($due);
    • $numDaysLate =
    •      (int)($daysLate->format('%R%d'));
    • echo 'Assignment was late by ' .
    •      $numDaysLate*-1 . ' days. ';

Card Set Information

Author:
slc53
ID:
326793
Filename:
php test3
Updated:
2016-12-13 19:57:54
Tags:
php test3
Folders:

Description:
php test3
Show Answers:

Home > Flashcards > Print Preview