Test php

PEAR, Smarty, ADOdb, OOP, PHP 5, XML, UML, Şabloane de proiectare, PHP-GTK.

Moderatori: coditza, Emil, Moderatori

XDYNX
Senior Member
Mesaje: 518
Membru din: Joi Iun 08, 2006 6:01 pm
Localitate: Pitesti
Contact:

Test php

Mesajde XDYNX » Lun Feb 04, 2019 11:15 am

Am si eu un test


The LeagueTable class tracks the score of each player
in a league. After each game, the player records their
score with the recordResult function.
The player's rank in the league is calculated using the
following logic:
1. The player with the highest score is ranked rst
(rank 1). The player with the lowest score is
ranked last.
2. If two players are tied on score, then the player
who has played the fewest games is ranked
higher.
3. If two players are tied on score and number of
games played, then the player who was rst in
the list of players is ranked higher.
Implement the playerRank function that returns the
player at the given rank.
For example:
$table = new LeagueTable(array('Mike',
'Chris', 'Arnold'));
$table->recordResult('Mike', 2);
$table->recordResult('Mike', 3);
$table->recordResult('Arnold', 5);
$table->recordResult('Chris', 5);
echo $table->playerRank(1);
All players have the same score. However, Arnold
and Chris have played fewer games than Mike,
and as Chris is before Arnold in the list of players, he



Cod: Selectaţi tot

class LeagueTable
{
    public function __construct(array $players)
    {
        $this->standings = [];
        foreach($players as $index => $p) {
            $this->standings[$p] = [
                'index'        => $index,
                'games_played' => 0,
                'score'        => 0
            ];
        }
    }

    public function recordResult(string $player, int $score) : void
    {
        $this->standings[$player]['games_played']++;
        $this->standings[$player]['score'] += $score;
       
    }

    public function playerRank(int $rank) : string
    {
     
       
       
    }
}

$table = new LeagueTable(array('Mike', 'Chris', 'Arnold'));
$table->recordResult('Mike', 2);
$table->recordResult('Mike', 3);
$table->recordResult('Arnold', 5);
$table->recordResult('Chris', 5);
echo $table->playerRank(1);


Iona14:6 Isus i-a zis: "Eu sunt Calea, Adevarul si Viata. Nimeni nu vine la Tatal decat prin Mine.

Înapoi la “PHP Avansat”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 9 vizitatori