<?php declare(strict_types=1); class ScoreAnalyzer { /** * @throws InvalidArgumentException */ public function __construct(private readonly int $score, private readonly int $number){ if($score < 0 || $score > 100){ throw new InvalidArgumentException('Score should be between 0 and 100'); } } public function analyzeScore(): Array { return [ 'Status' => $this->determineStatus(), 'Grade' => $this->calculateGrade(), 'Number' => $this->number, 'Type' => $this->findType(), ]; } private function determineStatus(): string { return $this->score >= 60 ? "pass" : "fail"; } private function calculateGrade(): string { return match (true) { $this->score < 60 => 'F', $this->score < 70 => 'D', $this->score < 80 => 'C', $this->score < 90 => 'B', default => 'A', }; } private function findType(): string { return $this->number % 2 === 0 ? "even" : "odd"; } } try{ $scoreAnalyzer = new ScoreAnalyzer(77, 4); $results =$scoreAnalyzer->analyzeScore(); printf("Status: %s \nGrade: %s \nNumber: %d \nType: %s", $results['Status'], $results['Grade'], $results['Number'], $results['Type']); } catch (Throwable $e) { echo $e->getMessage(); }
You have javascript disabled. You will not be able to edit any code.