Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class electronics{
- protected $power;
- protected $display;
- protected $powerState = 'off';
- function changePowerState (){
- switch ($this->powerState){
- case 'off':
- $this->powerState = 'on';
- break;
- case 'on':
- $this->powerState = 'off';
- break;
- default :
- $this->powerState = 'off';
- break;
- }
- }
- function getPowerState(){
- return $this->powerState;
- }
- function getPower() {
- return $this->power;
- }
- function setPower($type) {
- $this->power = $type;
- }
- function getDisplay() {
- return $this->display;
- }
- function setDisplay($type) {
- $this->display = $type;
- }
- function __construct($power,$display){
- $this->display = $display;
- $this->power = $power;
- }
- }
- class television extends electronics{
- protected $screenSize;
- protected $inputs = 1;
- protected $volume = 5;
- function increaseVolume(){
- if( $this->volume >= 10 ) {
- $this->volume = 10;
- }
- else{
- $this->volume = $this->volume +1;
- }
- }
- function decreaseVolume(){
- if( $this->volume <= 0 ) {
- $this->volume = 0;
- }
- else{
- $this->volume = $this->volume -1;
- }
- }
- function getScreenSize() {
- return $this->screenSize;
- }
- function getInputs() {
- return $this->inputs;
- }
- function setInputs($num) {
- $this->inputs = $num;
- }
- function getVolume() {
- return $this->volume;
- }
- function __construct($screenSize){
- $this->screenSize = $screenSize;
- }
- }
- class smartphone extends electronics{
- protected $screenSize;
- protected $mediaVolume = 5;
- protected $volume = 5;
- protected $storage;
- protected $apps = array();
- function increaseVolume(){
- if( $this->volume >= 10 ) {
- $this->volume = 10;
- }
- else{
- $this->volume = $this->volume +1;
- }
- }
- function decreaseVolume(){
- if( $this->volume <= 0 ) {
- $this->volume = 0;
- }
- else{
- $this->volume = $this->volume -1;
- }
- }
- function increaseMediaVolume(){
- if( $this->mediaVolume >= 10 ) {
- $this->mediaVolume = 10;
- }
- else{
- $this->mediaVolume = $this->mediaVolume +1;
- }
- }
- function decreaseMediaVolume(){
- if( $this->mediaVolume <= 0 ) {
- $this->mediaVolume = 0;
- }
- else{
- $this->mediaVolume = $this->mediaVolume -1;
- }
- }
- function getScreenSize() {
- return $this->screenSize;
- }
- function getVolume() {
- return $this->volume;
- }
- function addApp($item){
- $this->apps[] = $item;
- }
- function removeApp($item){
- array_splice($this->apps, array_search($item, $this->apps),1);
- }
- function getApps(){
- return $this->apps;
- }
- function __construct($screenSize, $storage){
- $this->screenSize = $screenSize;
- $this->storage = $storage;
- }
- }
- $device = new electronics('AC', 'digital');
- echo $device->getPower();
- echo '<BR>';
- echo $device->getPowerState();
- $set = new television('AC', 'LCD', 32);
- echo '<BR>';
- echo $set->getPowerState();
- echo '<BR>';
- echo $set->getVolume();
- echo '<BR>';
- $set->increaseVolume();
- echo $set->getVolume();
- echo '<BR>';
- $phone = new smartphone('AC','OLED',4.5, 64);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement