Question: Example metnioned

Example metnioned

## Player class with static method to return season of stats for a Player

class Player {

public static function get_stats() { $g1 = array("AB" => 3, "R" => 0, "H" => 1, "BB" => 1, "RBI" => 0); $g2 = array("AB" => 0, "R" => 1, "H" => 0, "BB" => 3, "RBI" => 0); $g3 = array("AB" => 4, "R" => 1, "H" => 2, "BB" => 1, "RBI" => 0); $g4 = array("AB" => 4, "R" => 2, "H" => 3, "BB" => 0, "RBI" => 3); $g5 = array("AB" => 2, "R" => 0, "H" => 2, "BB" => 1, "RBI" => 2); $games = array($g1, $g2, $g3, $g4, $g5);

return array("name" => "Talbot Jenkins", "games" => $games); } }

Example metnioned

Write a standalone PHP code that will compute a single baseball player's batting average based on the game data that has been collected for that player. (Note: Do not use HTML for this assignment.) Details You will be able to include a file containing a Player class definition and a static function that will return an associative array containing the player's name and his batting box score stats for each game he played in during the season. (Example file can be downloaded from here.) For each game of the season, you will find the following stats recorded: number of at bats (AB) runs made (R) hits (H) walks (BB) runs batted in (RBI) Your program should compute the totals for each of the above stats for the season and compute the overall batting average for the player. Print out the name of the player, the number of games he played in, and the five totals and one computed stat. Be sure to label the stats. Example output: Mike Trout Games played: 40 At bats: 123 Runs: 20 Hits: 27 Walks: 9 RBI: 16 Batting Avg.: .220

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!