Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.23 KB | None | 0 0
  1. <?php
  2.  
  3. class Privates
  4. {
  5.     private $id;
  6.     private $firstName;
  7.     private $secoundName;
  8.     private $salary;
  9.  
  10.     public function __construct($id, string $firstName, string $secoundName, float $salary)
  11.     {
  12.         $this->id = $id;
  13.         $this->firstName = $firstName;
  14.         $this->secoundName = $secoundName;
  15.         $this->salary = $salary;
  16.     }
  17.  
  18.     public function __toString()
  19.     {
  20.         $printSalary = number_format($this->salary, 2, '.', '');
  21.  
  22.         return " Name: {$this->firstName} {$this->secoundName} Id: {$this->id} Salary: {$printSalary}";
  23.     }
  24. }
  25.  
  26. $privates = [];
  27.  
  28. while (true) {
  29.     $input = trim(fgets(STDIN));
  30.     if ($input == "End") {
  31.         break;
  32.     }
  33.     $input = explode(" ", $input);
  34.  
  35.     if (count($input) == 5 && trim($input[0]) == "Private") {
  36.  
  37.         $id = trim($input[1]);
  38.         $firstName = trim($input[2]);
  39.         $secoundName = trim($input[3]);
  40.         $salary = number_format(floatval($input[4]), 2, '.', '');
  41.  
  42.         $newPrivate = new Privates($id, $firstName, $secoundName, $salary);
  43.  
  44.         echo "Name: {$firstName} {$secoundName} Id: {$id} Salary: {$salary}" . PHP_EOL;
  45.  
  46.         array_push($privates, $newPrivate);
  47.     }
  48.     if (count($input) == 6 && trim($input[0]) == "Commando") {
  49.  
  50.         $id = trim($input[1]);
  51.         $firstName = trim($input[2]);
  52.         $secoundName = trim($input[3]);
  53.         $salary = number_format(floatval($input[4]), 2, '.', '');
  54.         $corps = trim($input[5]);
  55.  
  56.         echo "Name: {$firstName} {$secoundName} Id: {$id} Salary: {$salary}" . PHP_EOL;
  57.         echo "Corps: {$corps}" . PHP_EOL;
  58.         echo "Missions:" . PHP_EOL;
  59.  
  60.     }
  61.  
  62.     if (count($input) == 7 && trim($input[0]) == "LeutenantGeneral") {
  63.  
  64.         $id = trim($input[1]);
  65.         $firstName = trim($input[2]);
  66.         $secoundName = trim($input[3]);
  67.         $salary = number_format(floatval($input[4]), 2, '.', '');
  68.         $privateID1 = trim($input[5]);
  69.         $privateID2 = trim($input[6]);
  70.  
  71.         echo "Name: {$firstName} {$secoundName} Id: {$id} Salary: {$salary}" . PHP_EOL;
  72.     }
  73. }
  74. if(count($privates)!=0){
  75.     echo "Privates:" . PHP_EOL;
  76.     foreach ($privates as $privatePerson) {
  77.         echo $privatePerson . PHP_EOL;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement