March 13 - Build a Score Tracking Program in Ruby
This guide examines a seemingly simple program, however in order to properly implement the solution you will be required to use a number of key Ruby programming techniques. In this exercise you'll build out a scoreboard program that generates an inning by inning score for a baseball team along with a dynamic total.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Build a program that keeps track of a baseball team's score on an inning by inning basis along with totaling up the total runs.

Exercise Description

Build a Ruby class that works like a scoreboard for a 9 inning game. This means that the class should start a game where every inning has 0 runs and as the game goes on, runs can be added to runs, which also changes the total.

Example Game

team = Scoreboard.new('Astros')
team.score # => {"Astros"=>{1=>0, 2=>0, 3=>0, 4=>0, 5=>0, 6=>0, 7=>0, 8=>0, 9=>0}}
team.add_run inning: 3
team.add_run inning: 3
team.add_run inning: 5
team.add_run inning: 8
team.score # => {"Astros"=>{1=>0, 2=>0, 3=>2, 4=>0, 5=>1, 6=>0, 7=>0, 8=>1, 9=>0}}
team.generate_total # => 4

Real World Usage

This may seem like a simple program to build out. However, to properly implement the program to pass all of the tests you will need to work with nested hashes, maintaining value states for data, configure a reader, and perform calculations on nested hash values. This is one of my favorite coding questions to give devs that I'm interviewing since it reveals their knowledge of hashes and how to work with classes.

Test Cases

Code File