Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Car
- {
- private $model;
- private $engines;
- private $weight;
- private $color;
- public function __construct(string $model, Engine $engines, string $weight, string $color)
- {
- $this->model = $model;
- $this->engines = $engines;
- $this->weight = $weight;
- $this->color = $color;
- }
- public function getModel(): string
- {
- return $this->model;
- }
- public function getEngine(): Engine
- {
- return $this->engines;
- }
- public function getWeight(): string
- {
- return $this->weight;
- }
- public function getColor(): string
- {
- return $this->color;
- }
- }
- class Engine
- {
- private $model;
- private $power;
- private $displacement;
- private $efficiency;
- public function __construct(string $model, int $power, string $displacement, string $efficiency)
- {
- $this->model = $model;
- $this->power = $power;
- $this->displacement = $displacement;
- $this->efficiency = $efficiency;
- }
- public function getModel(): string
- {
- return $this->model;
- }
- public function getPower(): int
- {
- return $this->power;
- }
- public function getDisplacement(): string
- {
- return $this->displacement;
- }
- public function getEfficiency(): string
- {
- return $this->efficiency;
- }
- }
- $carList = [];
- $engineList = [];
- $n = intval(readline());
- while ($n-- > 0) {
- $input = explode(" ", readline());
- $model = $input[0];
- $power = intval($input[1]);
- if (count($input) == 4) {
- $displacement = $input[2];
- $efficency = $input[3];
- } else if (count($input) == 3) {
- try {
- $displacement = "n/a";
- $efficency = $input[2];
- } catch (Exception $e) {
- $displacement = $input[2];
- $efficency = "n/a";
- }
- }
- $engines = new Engine($model, $power, $displacement, $efficency);
- $engineList[] = $engines;
- }
- $m = intval(readline());
- while ($m-- > 0) {
- $input = explode(" ", readline());
- $model = $input[0];
- $engineName = $input[1];
- if (count($input) == 4) {
- $weight = $input[2];
- $color = $input[3];
- } else if (count($input) == 3) {
- try {
- $weight = "n/a";
- $color = $input[2];
- } catch (Exception $e) {
- $weight = $input[2];
- $color = "n/a";
- }
- }
- if (key_exists($engineName, $engineList)) {
- $current = '';
- }
- $carsCurrent = new Car($model, $engineName, $weight, $color);
- $carList[] = $carsCurrent;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement