Question: You are to develop a program in the Go programming language to read Baseball Player objects from an input file into a list/collection. You are
You are to develop a program in the Go programming language to read Baseball Player objects from an input file into a list/collection. You are to store the players in a collection in such a way that when they are displayed to the screen, they are in sorted order by lastname (then firstname to break name ordering ties).
Each line of the data file will contain one player's name and stats.
firstname lastname plateappearances atbats singles doubles triples homeruns walks hitbypitch
You may assume there are no errors in the data.
Operations/Computations:
-
Compute batting average: this is the sum of the hits (singles, doubles, triples, home runs) divided by the number of at-bats.
-
Compute slugging percentage. The slugging percentage is a weighted average. It is computed by:
= +2+3+4h
-
Compute the on base percentage. OBP is the sum of all hits, walks and hit-by-pitch divided by the number of plate appearances.
-
Compute the team's overall batting average.Summary of Operation
-
Prompt the user for the input file name. DO NOT hardcode file names into your program.
-
Open input file
-
Read each player and add them to your List.
-
Keep track of the number of items in the list
-
Write a report summary line to the screen.
-
Write each item from the list formatted to the screen, along with any other output required by
the assignment
Sample Input File
Hank Aaron 13941 12364 2294 624 98 755 1402 32 Chipper Jones 10614 8984 1671 549 38 468 1512 18 Ty Cobb 13099 11434 3053 724 295 117 1249 94 Jonny Bench 8674 7658 1254 381 24 389 891 19 Tony Gwynn 10232 9288 2378 543 85 135 434 24 John Smoltz 1167 948 118 26 2 5 79 3
This is in GoLang
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
