QuestionQuestion

Problem Statement
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. I will not leave data out or put non-numeric data in numeric fields. You must read until the end of the file is found.

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 ∗ 𝑡𝑟𝑖𝑝𝑙𝑒𝑠 + 4 ∗ ℎ𝑜𝑚𝑒𝑟𝑢𝑛𝑠 / 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑎𝑡 𝑏𝑎𝑡𝑠

• 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

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package main

// import library
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
)

// Think about data objects and what they contain. Even though GO is not fully object-oriented (as
//in inheritance) we should be using good design practices.
type player struct {
firstname string
lastname string
plateappearances int
atbats int
singles int
doubles int
triples int
homeruns int
walks int
hitbypitch int
average float32
slugging float32
onbase float32
}

/**
* calculate average, slugging and onbase of a player
* parameter : *player a pointer to player so that we could update its value
*/
func calculation(p *player) {
var total = 0

// Compute batting average: this is the sum of the hits (singles, doubles, triples, home runs)
//divided by the number of at-bats.
total = p.doubles + p.singles + p.triples + p.homeruns
p.average = float32(total) / float32(p.atbats)

// Compute slugging percentage. The slugging percentage is a weighted average.
total = p.singles + 2 * p.doubles + 3 * p.triples + 4 * p.homeruns
p.slugging = float32(total) / float32(p.atbats)

// Compute the on base percentage. OBP is the sum of all hits, walks and hit-by-pitch divided by
//the number of plate appearances.

total = p.homeruns + p.triples + p.singles + p.hitbypitch + p.doubles + p.walks
p.onbase = float32(total) / float32(p.plateappearances)
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$35.00 $17.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats