Advertisement
ph4x35ccb

classe agregada

Mar 23rd, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.09 KB | None | 0 0
  1. index arquivo 1 php
  2. <html>
  3. <head>
  4.     <title></title>
  5. </head>
  6. <body>
  7. <?php
  8. require_once 'pessoa.php';
  9. require_once 'livro.php';
  10. echo "<pre>";
  11.  
  12. $p[0]=new Pessoa("Pedro",22,"M");
  13. $p[1]=new Pessoa("Maria",31,"F");
  14.  
  15.  
  16. $l[0]=new Livro("PHP Basico","Jose Silva",300,$p[0]);
  17. $l[1]=new Livro("POO","Maria Sousa",500, $p[0]);
  18. $l[2]=new Livro("PHP avancado","Ana Paula",800,$p[1]);
  19.  
  20.  
  21. //print_r($l[0]);
  22. $l[0]->abrir();
  23. $l[0]->folhear(80);
  24. $l[0]->avancarPag();
  25. $l[0]->detalhes();
  26.  
  27. echo "</pre>";
  28. ?>
  29. </body>
  30. </html>
  31.  
  32. classe pessoa arquivo 2 php
  33. <?php
  34.  
  35. class Pessoa{
  36.  
  37. private $nome;
  38. private $idade;
  39. private $sexo;
  40.  
  41.  
  42. public function fzerAniversario(){
  43.     $this->idade++;
  44. }
  45.  
  46. function __construct($nome,$idade,$sexo){
  47.     $this->nome=$nome;
  48.     $this->idade=$idade;
  49.     $this->sexo=$sexo;
  50. }
  51.  
  52. public function getNome(){
  53.     return $this->nome;
  54. }
  55. public function getIdade(){
  56.     return $this->idade;
  57. }
  58. public function getSexo(){
  59.     return $this->sexo;
  60. }
  61.  
  62. public function setNome($nome){
  63.     $this->nome=$nome;
  64. }
  65. public function setIdade($idade){
  66.     $this->idade=$idade;
  67. }
  68. public function setSexo($sexo){
  69.     $this->sexo=$sexo;
  70. }
  71.  
  72. }
  73.  
  74.  
  75. ?>
  76. classe agregada livro arquivo 3 php
  77. <?php
  78.  
  79. require_once 'pessoa.php';
  80. require_once 'publicacao.php';
  81.  
  82. class Livro implements Publicacao{
  83.  
  84. private $titulo;
  85. private $autor;
  86. private $totPaginas;
  87. private $pagAtual;
  88. private $aberto;
  89. private $leitor;
  90.  
  91. public function detalhes(){
  92.     echo "Livro ".$this->titulo." escrito por ".$this->autor;
  93.     echo "<br>Paginas: ".$this->totPaginas." atual ".$this->pagAtual;
  94.     echo "<br>Sendo lido por ".$this->leitor->getNome();
  95. }
  96.  
  97. public function __construct($titulo,$autor,$totPaginas,$leitor){
  98.     $this->titulo=$titulo;
  99.     $this->autor=$autor;
  100.     $this->totPaginas=$totPaginas;
  101.     $this->aberto=false;
  102.     $this->pagAtual=0;
  103.     $this->leitor=$leitor;
  104. }
  105.  
  106. public function getTitulo(){
  107.     return $this->titulo;
  108. }
  109. public function getAutor(){
  110.     return $this->autor;
  111. }
  112. public function getTotPaginas(){
  113.     return $this->totPaginas;
  114. }
  115. public function getPagAtual(){
  116.     return $this->pagAtual;
  117. }
  118. public function getAberto(){
  119.     return $this->aberto;
  120. }
  121. public function getLeitor(){
  122.     return $this->leitor;
  123. }
  124.  
  125. public function setTitulo(){
  126.     $this->titulo=$titulo;
  127. }
  128. public function setAutor($autor){
  129.     $this->autor=$autor;
  130. }
  131. public function setTotPaginas($totPaginas){
  132.     $this->totPaginas=$totPaginas;
  133. }
  134. public function setPagAtual($pagAtual){
  135.     $this->pagAtual=$pagAtual;
  136. }
  137. public function setLeitor($leitor){
  138.     $this->leitor=$leitor;
  139. }
  140.  
  141. public function abrir(){
  142.     $this->aberto=true;
  143. }
  144. public function avancarPag(){
  145.     $this->pagAtual++;
  146. }
  147. public function fechar(){
  148.     $this->aberto=false;
  149. }
  150. public function folhear($p){
  151.     if($p>$this->totPaginas){
  152.         $this->pagAtual=0;
  153.     }else{
  154.         $this->pagAtual=$p;
  155.     }
  156. }
  157. public function voltarPag(){
  158.     $this->pagAtual--;
  159. }
  160.  
  161.  
  162.  
  163. }
  164. ?>
  165.  
  166. imprementaçao publicaçao arquivo 4 php
  167.  
  168. <?php
  169.  
  170. interface Publicacao{
  171.  
  172. public function abrir();
  173. public function fechar();
  174. public function folhear($p);
  175. public function avancarPag();
  176. public function voltarPag();
  177. }
  178.  
  179. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement