Lab 7

profilejahguy
lab7.zip

lab7/Author.class.php

<?php class Author{ private $firstName; private $lastName; private $country; public function __construct($f,$l,$c){ $this->firstName=$f; $this->lastName=$l; $this->country=$c; } public function summary(){ $abbr=substr($this->lastName,0,1); return $this->firstName.",".strtoupper($abbr).".(".$this->country.")"; } } ?>

lab7/Book.class.php

<?php class Book{ private $title; private $yearPublished; private $author; private static $counter=0; const MAX=4; public function __construct($t,$a,$y){ $this->title=$t; $this->author=$a; $this->yearPublished=$y; self::$counter++; } public function __destruct(){ } public function summary(){ return $this->author->summary()." - ".$this->title." (".$this-> yearPublished.")<br/>"; } public function remaining(){ if(self::$counter<self::MAX){ return "".(self::MAX-self::$counter)."<br/>"; } else{ return "Limit reached."; } } } ?>

lab7/index.html

lab7/raccoon.js

function Raccoon(n,d ,p){ Reviewable.call(this); this.name= n; this.birthdate= d; this.image= p; this.reviews= []; }

lab7/reviewable.js

function Reviewable(){ this.reviews= []; this.countReviews = function() { return this.reviews.length; } this.addReview = function(reviewer, review) { this.reviews.push({ reviewer: reviewer, review: review }); } }

lab7/testBook.php

<?php function loadClass($className) { echo "<div>Loading class: $className</div>"; require ($className . ".class.php"); } spl_autoload_register('loadClass'); $author=new Author("Name","last",1974); $book=new Book("Book1",$author,1990); echo $book->summary(); echo Book::remaining(); $book=new Book("Book1",$author,1990); echo Book::remaining(); $book=new Book("Book1",$author,1990); //require statement argument is filename //code runs when first object of a class is created. //echo a string in constructor to test hypothesis. ?>