Advertisement
smaction

Create Class PHP II

Feb 8th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.83 KB | None | 0 0
  1. <?php
  2. class electronics{
  3.    
  4.     protected $power;
  5.     protected $display;
  6.     protected $powerState = 'off';
  7.    
  8.     function changePowerState (){
  9.         switch ($this->powerState){
  10.             case 'off':
  11.                 $this->powerState = 'on';
  12.                 break;
  13.             case 'on':
  14.                 $this->powerState = 'off';
  15.                 break;
  16.             default :
  17.                 $this->powerState = 'off';
  18.               break;
  19.         }
  20.     }
  21.    
  22.     function getPowerState(){
  23.         return $this->powerState;
  24.     }
  25.    
  26.     function getPower()  {
  27.         return $this->power;    
  28.     }
  29.    
  30.     function setPower($type) {
  31.         $this->power = $type;
  32.     }
  33.    
  34.     function getDisplay()  {
  35.         return $this->display;
  36.     }
  37.    
  38.     function setDisplay($type) {
  39.         $this->display = $type;
  40.     }
  41.    
  42.     function __construct($power,$display){
  43.         $this->display = $display;
  44.         $this->power = $power;
  45.     }
  46.    
  47. }
  48.  
  49.  
  50. class television extends electronics{
  51.    
  52.     protected $screenSize;
  53.     protected $inputs = 1;
  54.     protected $volume = 5;
  55.  
  56.    
  57.     function increaseVolume(){
  58.         if( $this->volume >= 10 ) {
  59.             $this->volume = 10;
  60.         }
  61.         else{
  62.             $this->volume = $this->volume +1;
  63.         }
  64.     }
  65.    
  66.     function decreaseVolume(){
  67.         if( $this->volume <= 0 ) {
  68.             $this->volume = 0;
  69.         }
  70.         else{
  71.             $this->volume = $this->volume -1;
  72.         }
  73.     }
  74.    
  75.     function getScreenSize()  {
  76.         return $this->screenSize;
  77.     }
  78.    
  79.     function getInputs()  {
  80.         return $this->inputs;
  81.     }
  82.    
  83.     function setInputs($num) {
  84.         $this->inputs = $num;
  85.     }
  86.    
  87.     function getVolume()  {
  88.         return $this->volume;
  89.     }
  90.    
  91.     function __construct($screenSize){
  92.         $this->screenSize = $screenSize;
  93.     }
  94.    
  95. }
  96.  
  97. class smartphone extends electronics{
  98.    
  99.     protected $screenSize;
  100.     protected $mediaVolume = 5;
  101.     protected $volume = 5;
  102.     protected $storage;
  103.     protected $apps = array();
  104.    
  105.     function increaseVolume(){
  106.         if( $this->volume >= 10 ) {
  107.             $this->volume = 10;
  108.         }
  109.         else{
  110.             $this->volume = $this->volume +1;
  111.         }
  112.     }
  113.    
  114.     function decreaseVolume(){
  115.         if( $this->volume <= 0 ) {
  116.             $this->volume = 0;
  117.         }
  118.         else{
  119.             $this->volume = $this->volume -1;
  120.         }
  121.     }
  122.    
  123.     function increaseMediaVolume(){
  124.         if( $this->mediaVolume >= 10 ) {
  125.             $this->mediaVolume = 10;
  126.         }
  127.         else{
  128.             $this->mediaVolume = $this->mediaVolume +1;
  129.         }
  130.     }
  131.    
  132.     function decreaseMediaVolume(){
  133.         if( $this->mediaVolume <= 0 ) {
  134.             $this->mediaVolume = 0;
  135.         }
  136.         else{
  137.             $this->mediaVolume = $this->mediaVolume -1;
  138.         }
  139.     }
  140.    
  141.     function getScreenSize()  {
  142.         return $this->screenSize;
  143.     }
  144.    
  145.     function getVolume()  {
  146.         return $this->volume;
  147.     }
  148.    
  149.     function addApp($item){
  150.         $this->apps[] = $item;
  151.     }
  152.    
  153.     function removeApp($item){
  154.        array_splice($this->apps, array_search($item, $this->apps),1);
  155.     }
  156.    
  157.     function getApps(){
  158.        return $this->apps;
  159.     }
  160.    
  161.     function __construct($screenSize, $storage){
  162.         $this->screenSize = $screenSize;
  163.         $this->storage = $storage;
  164.     }
  165.    
  166. }
  167.  
  168. $device = new electronics('AC', 'digital');
  169.  
  170. echo $device->getPower();
  171. echo '<BR>';
  172. echo $device->getPowerState();
  173.  
  174. $set = new television('AC', 'LCD', 32);
  175. echo '<BR>';
  176. echo $set->getPowerState();
  177. echo '<BR>';
  178. echo $set->getVolume();
  179. echo '<BR>';
  180. $set->increaseVolume();
  181. echo $set->getVolume();
  182. echo '<BR>';
  183.  
  184. $phone = new smartphone('AC','OLED',4.5, 64);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement