The Ruby program bstats.rb
contains
code to read sample.txt
and print
player names. Revise this code to print on-base percentage defined as the
number of hits plus the number of walks divided by the number of at-bats
plus the number of walks. Display batter names followed by their on-base
percentage (rounded to 4 digits after the decimal); for example:
Hank Aaron: 0.4117 Barry Bonds: 0.4428(These are the statistics for the first two entries in
sample.txt
.)
For full credit,
your solution must implement a method
called on_base_percentage
that computes the statistic for each
player. As usual, print 0 if the player has no at-bats or walks.
Submit your code to esubmit.msoe.edu as ex2bb. You are done when you have zero differences.
This code uses programming constructs that have not yet been discussed in class. You can use resources like class notes, the chapters "Classes, Objects, and Variables" and "Containers, Blocks, and Iterators" in Programming Ruby, and Stack Overflow to help figure out the code you are given and to help with making changes. You can also simply guess and experiment!