Skip to content

Radio Test Driver (Version 2)

useRadio.php - OOP in PHP: Complete Code Listing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
    require_once('Radio.php');

    $car_radio = new Radio();
    $boat_radio = new Radio();

    $car_radio->setPowered(true);
    $car_radio->setVolume(4);
    $car_radio->setChannel(88.6);

    $boat_radio->setPowered(true);
    $boat_radio->setVolume(11);
    $boat_radio->setChannel(430);

    echo 'My car radio is ';

    if ($car_radio->getPowered())
    {
        echo 'turned on';
    }
    else
    {
        echo 'turned off';
    }

    echo ' with the volume set to ' . $car_radio->getVolume() . ', ';
    echo ' and the channel set to ' . $car_radio->getChannel() . '.<br /><br />';
    echo 'My boat radio is ';

    if ($boat_radio->getPowered())
    {
        echo 'turned on';
    }
    else
    {
        echo 'turned off';
    }

    echo ' with the volume set to ' . $boat_radio->getVolume() . ', ';
    echo ' and the channel set to ' . $boat_radio->getChannel() . '.';