Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.18 KB | None | 0 0
  1. <?php
  2.     class AnggotaKeluarga
  3.     {
  4.         private $name;
  5.  
  6.         public function __construct($name)
  7.         {
  8.             $this->name = $name;
  9.         }
  10.                
  11.         public function getName()
  12.         {
  13.             return $this->name;
  14.         }
  15.     }
  16.  
  17.     class Keluarga
  18.     {
  19.         private $father;
  20.         private $mother;
  21.         private $children;
  22.  
  23.         public function __construct($father, $mother)
  24.         {
  25.             $this->father = $father;
  26.             $this->mother = $mother;
  27.             $this->children = [];
  28.         }
  29.  
  30.         public function addChildren($child)
  31.         {
  32.             $this->children[] = $child;
  33.         }
  34.                
  35.         public function getFatherName()
  36.         {
  37.             return $this->father->getName();
  38.         }
  39.         public function getMotherName()
  40.         {
  41.             return $this->mother->getName();
  42.         }
  43.         public function getChildren()
  44.         {
  45.             return $this->children;
  46.         }
  47.     }
  48.        
  49.         $salsa = new AnggotaKeluarga('Salsabila');
  50.         $ayahSalsa = new AnggotaKeluarga('Ayah Salsa');
  51.         $ibuSalsa = new AnggotaKeluarga('Ibu Salsa');
  52.         $keluargaSalsa = new Keluarga($ayahSalsa, $ibuSalsa);
  53.                 $keluargaSalsa->addChildren($salsa);
  54. ?>
  55.  
  56. <!DOCTYPE html>
  57. <html lang="en">
  58. <head>
  59.     <meta charset="UTF-8">
  60.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  61.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  62.     <title>Test</title>
  63. </head>
  64. <body>
  65.     <svg height="150" width="170">
  66.         <text x="0" y="20" fill="red"><?= $keluargaSalsa->getFatherName() ?></text>
  67.         <text x="90" y="20" fill="red"><?= $keluargaSalsa->getMotherName() ?></text>
  68.         <line x1="25" y1="25" x2="25" y2="75" style="stroke:rgb(255,0,0);stroke-width:3" />
  69.         <line x1="125" y1="25" x2="125" y2="75" style="stroke:rgb(255,0,0);stroke-width:3" />
  70.         <line x1="23" y1="75" x2="127" y2="75" style="stroke:rgb(255,0,0);stroke-width:3" />
  71.         <line x1="75" y1="75" x2="75" y2="125" style="stroke:rgb(255,0,0);stroke-width:3" />
  72.         <text x="32.5" y="150" fill="red"><?= $keluargaSalsa->getChildren()[0]->getName() ?></text>
  73.     </svg> <br>
  74. </body>
  75. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement