Beispiel #1
0
<?php

require_once 'autoload.php';
$car1 = new Car('BMW', true, 'black', 340000, 250);
$car1->setCurrentSpeed(100);
$car1->setCurrentGear(4);
$car2 = new Car('Audi', false, 'grey', 280000, 260);
$car2->setCurrentSpeed(150);
$car2->setCurrentGear(5);
echo "Gear is: ", $car1->getCurrentGear(), " and the speed is: ", $car1->getCurrentSpeed(), PHP_EOL;
$car1->changeGear(5);
$car1->accelerate();
echo "Now the gear is: ", $car1->getCurrentGear(), " and the speed is: ", $car1->getCurrentSpeed(), PHP_EOL;
$shop = new CarShop();
$shop->addCar($car1);
$shop->addCar($car2);
$shop->showAllCarsInTheShop();
Beispiel #2
0
<?php

require_once 'autoload.php';
$person = new Person('Nikol', 121213048, false, 500000);
$person2 = new Person('Ivan', 12123048, true, 200000);
$car = new Car('Honda Accord', 36000, true, 'white', 260);
$car2 = new Car('Nissan GTR', 150000, true, 'black', 320);
$carShop = new CarShop();
$carShop->addCar($car);
$carShop->addCar($car2);
echo ' The price of the ' . $car->getModel() . ' for scrap is ' . $car->calculatePriceForScrap(10000) . '.', PHP_EOL;
echo $person->buyCar($car2), PHP_EOL;
echo 'After buying a new ' . $person->getCar()->getModel() . ', ' . $person->getName() . ' has ' . $person->getMoney() . ' money left.', PHP_EOL;
echo 'After selling the car for scrap, ' . $person->getName() . ' has ' . $person->sellCarForScrap(15000) . ' money left.', PHP_EOL;
$car2->changeOwner($person2);
echo 'The new owner of the ' . $car2->getModel() . ' is: ' . $car2->getOwner()->getInfo();
Beispiel #3
0
<?php

spl_autoload_register(function ($class) {
    require_once 'lib' . DIRECTORY_SEPARATOR . $class . '.php';
});
header('Content-type: application/json; charset=utf-8');
try {
    $carShop = new CarShop();
    $method = $_SERVER['REQUEST_METHOD'];
    if ($method === 'GET') {
        if (isset($_GET['id'])) {
            print json_encode($carShop->getTypeById($_GET['id']));
        } else {
            if (isset($_GET['type'])) {
                print json_encode($carShop->searchByType($_GET['type']));
            } else {
                print json_encode($carShop->listAll());
            }
        }
    }
    if ($method === 'POST') {
        print json_encode($carShop->preorder($_POST));
    }
} catch (SoapFault $e) {
    http_response_code(400);
    print json_encode(['error' => $e->getMessage(), 'response' => $carShop->getLastResponse()]);
}
Beispiel #4
0
<?php

require_once 'autoload.php';
$owner1 = new Person('Petar Kunchev', 25, true);
$owner1->setMoney(300);
$car1 = new Car('BMW', true, 'red', 1000, 230);
$car2 = new Car('Mercedes', true, 'white', 1000, 260);
$car3 = new Car('Audi', false, 'black', 1000, 240);
$car4 = new Car('VW', false, 'green', 800, 160);
// echo $car1->showCarInfo() . PHP_EOL;
$carshop = new CarShop($car1, $car2, $car3);
$carshop->showAllCarsInTheShop();
$carshop->sellNextCar($owner1);
$carshop->showAllCarsInTheShop();
// $carshop->showAllCarsInTheShop();
// $carshop->addCar($car4);
// $carshop->showAllCarsInTheShop();
// $owner1->setMoney(50000);
// echo $owner1->getMoney() . PHP_EOL;
// $owner1->buyCar($car1);
// echo $owner1->getMoney() . PHP_EOL;
// $owner1->sellCarForScrap(300);
// echo $owner1->getMoney() . PHP_EOL;
// $car1->changeColor('black');
// $car1->changeGear(1);
// $car1->accelerate();
// $car1->accelerate();
// echo $car1->showCarInfo() . PHP_EOL;
//$car1->changeGearUp();
//echo 'Current gear is ' . $car1->getCurrentGear(), PHP_EOL;
//
//$car1->changeGearDown();
//echo 'Current gear is ' . $car1->getCurrentGear(), PHP_EOL;
//
//$car1->changeGear(2);
//echo 'Current gear is ' . $car1->getCurrentGear(), PHP_EOL;
//
//$car1->changeColor('blue');
//echo 'Current color is ' . $car1->getColor(), PHP_EOL;
$car11 = new Car('Mazda', true, 'brown', 50000, 350);
$car12 = new Car('Suzuki', true, 'blue', 40000, 300);
$car13 = new Car('Hyundai', false, 'pink', 30000, 250);
$car14 = new Car('Mazda', true, 'brown', 50000, 350);
$buyer1 = new Person('Georgi', 8956456231, true);
$buyer1->setMoney(50000);
$carShop = new CarShop($car11, $car12);
$carShop->addCar($car13);
$carShop->addCar($car14);
print_r($carShop->getNextCar());
$carShop->sellNextCar($buyer1);
$carShop->removeCar($car11);
$carShop->showAllCarsInTheShop();
print_r($buyer1);
print_r($carShop->getNextCar());
print_r($carShop->getNextCar());
print_r($carShop->getNextCar());
print_r($carShop->getNextCar());
$carShop->addCar($car11);
$carShop->showAllCarsInTheShop();