• Compiling and running more complex Go programs
  • Experience with packages
  • Usage of different Go tools
    • go install
  • Experience using interface types

Relevant Resources


Dr. Doofenshmirtz used the Smartness-Determinator to find the smartest book he could find. He fell asleep listening to the audiobook and awoke the next morning to find his vocabulary severely limited.

Our Story Continues

You arrive at work well-rested and ready to program. A sleepy minion (Stuart possibly) with a headset stumbles past you holding a trembling cup of coffee. It looks up at you with a grim expression.

As you proceed to your desk, you see several minions in similar conditions. They’re all babbling over the phone – taking orders from various customers. The floor is covered with adding machine tape Stuart wanders to his desk, picks up a stack of messy spreadsheets and walks with you toward your office. Droplets of coffee spill onto the floor as he tries to hold it still in his tiny, tired hands.

You arrive at your desk and turn around. Stuart is standing there very still.

As he opens his mouth to speak, he collapses. He starts snoring.

It is very awkward.

Your Task

The minions are overwhelmed with inator-related financial data to process. Your task is to develop a stock-ticker-like command line application to make their lives a little easier. For this assignment, you are to do the following:

  • Finish implementing a Go program that….
    • Accepts the path of an input file on the command line
    • Calculates the value of inators over time
    • Reports the inator values in US Dollars

Refer to this assignment’s rubric for further description of point values for completed tasks.

Application Description

Your application should work something like this:

If we don’t provide a path to a file, we get an error and the usage.

$ ./bin/ticker
Expected exactly one file path.

Usage: ./bin/ticker FILE

This program parses JSON-encoded stock information and prints it in an
easy-to-read way.

It accepts one file path as a positional argument.

If we give it a valid filename, we see the inator values over time.

# If we provide a filename, we see the values of the inators over time
$ ./bin/ticker data.json
19 Nov 17 15:00 CST
    Inator                 Trades               Average Value (USD)
    hitch-a-ride-inator    [$194.39]            $194.39
    ohugconfetti-inator    [$752.36 $771.43]    $761.89
    stick-inator           [$947.44 $942.79]    $945.12
    suck-inator            [$222.17]            $222.17

19 Nov 17 16:00 CST
    Inator                 Trades               Average Value (USD)
    hitch-a-ride-inator    [$216.18 $222.05]    $219.12
    up-inator              [$70.21 $74.89]      $72.55

Program Design

You will be finishing the implementation of a Go program. The starter code is actually pretty complete. Here’s what you still have to do:

  • Ensure that the money.Chf, money.Ddb, money.Gbp, money.Plg, and money.Usd types all implement the following interfaces:
  • Ensure that the stocks.Events type implements the following interface:

Be sure to read the “Approaching this Assignment” section of this post for advice.

Concurrency Requirements

This time, there’s no need to spin up goroutines.

File Format

Files are all JSON-encoded data:

    "At": "2017-11-19T16:17:03.933123977-06:00",
    "Inator": "decker-inator",
    "Value": "497.37 Fr."
    "At": "2017-11-19T16:23:03.933123977-06:00",
    "Inator": "outside-in-inator",
    "Value": "798.62 Fr."
    "At": "2017-11-19T16:29:03.933123977-06:00",
    "Inator": "stick-inator",
    "Value": "924 Goo-Koos"
  • The file contains a single JSON array.
  • Each element in the JSON array is a JSON object with three fields and can be represented as a stocks.Event.
    • The At field indicates at what time the trade occurred.
    • The Inator field indicates the name of the inator.
    • The Value field indicates the value of the inator.
      • The value is in one of the following currencies:
        • Swiss Franc (CHF)
          • $1 is 0.99 Franc
          • Truncate any value smaller than 0.01 Franc.
            • 550.33 Fr. / 0.99 = $555.888... -> 555.88
        • Drusselsteinian Doonkelberry (DDB)
          • $1 is 10 Berries
          • Truncate any value smaller than 0.01 Berries.
            • 550.33 Berries / 10 = $55.033 -> $55.03
        • British Pound Sterling (GBP)
          • $1 is 0.76 Pounds
          • Truncate any value smaller than £0.01.
            • £550.33 / 0.76 = $724.11842 -> $724.11
        • Portlandian Goo-Koo1 (PLG)
          • $1 is 1 Goo-Koo
          • Truncate any value smaller than 1 Goo-Koo, since we can’t divide ping-ping balls.
            • 550 Goo-Koos = $550
            • $550.33 = 550 Goo-Koos
        • US Dollar (USD)
          • $1 is $1
      • Ignore the fact that currency values change daily.

If you have questions about other formatting assumptions, be sure to email your instructor.

Error Handling

The user-relevant error handling is all done for you.

As you implement each of the interfaces described above, you’ll find the need to handle various errors. Make sure your error handling agrees with what the interface expects. If you have questions about how to handle errors, just ask.

Automated Tests

There are a bunch of automated test files provided for you. You’re welcome to use them to sanity check your code.

You’re also welcome to write your own unit tests, too.

Working on the Program

Setting up the right version of Go

Refer to the setup instructions for Homework 7.

Running it

You’ll need to compile your program before you run it this time. go run won’t cut it.

$ GOROOT="$(pwd)/go" GOPATH="$(pwd)" ./go/bin/go install ticker

$ ./bin/ticker data.json
# Program output ...

You can also use go build, but go install keeps things organized by dropping the built executable in the local bin directory.


Make sure your program’s output looks like the sample output.

Proper Go Style

You should rely on go fmt to format your code properly. It will modify your source file in place, so make sure your source files aren’t open in an editor when you run it. Some editors react badly when an open file is changed by another program.

It’s like having the carpet pulled out from underneath you. Some editors are graceful, others just flail around and leave backup files all over the place.

# Pass `go fmt` the names of the packages
$ GOROOT="$(pwd)/go" GOPATH="$(pwd)" ./go/bin/go fmt money stocks ticker

Further Details

Approaching this Assignment

You should tackle this assignment as follows:

  • Read this entire posting and docs (you’ll likely do this more than once).
  • Clone the code.
  • Run setup.sh to download, verify, and unpack Go 1.9.2.
  • Implement all required interfaces.
  • Make sure your code passes the provided unit tests.
  • Make sure your output matches the sample output for the given commands.
  • Make sure your code is formatted.
    • Use go fmt.
  • Submit!
    • Check that your submission is on GitLab.

Important Notes

  • All of your changes will be in the money and stocks packages.
    • Keep your code organized!
  • Your program’s output must match the format of the sample output.
  • If you are in a pinch and plan to submit partially-functioning code, make sure it compiles. If you submit code that does not compile, it becomes very difficult to assign partial credit in other rubric categories.

Point Value

This assignment is worth 100 points. It will be graded according to the following rubric:

Feature Points Possible Mostly or completely incorrect (0% of points possible) Needs improvement (50% of points possible) Adequate, but still some deficiencies (75% of points possible) Mostly or completely correct (100% of points possible)
Unit Testing          
Passes instructor unit tests 15 -15 -8 -4 0
fmt.Stringer is implemented correctly 10 -10 -5 -3 0
money.Dollarer is implemented correctly 10 -10 -5 -3 0
json.Unmarshaler is implemented correctly 10 -10 -5 -3 0
sort.Interface is implemented correctly 10 -10 -5 -3 0
Program compiles successfully (no errors) 5 -5 0
Program runs without runtime errors (no runtime panics) 10 -10 0
Program output matches expected output 10 -10 -5 -3 0
Source has been formatted with go fmt 10 -10 0
Code Review (well-documented, implementation is straightforward, etc.) 10 -10 -5 -3 0
Points possible 100        

Each cell indicates how many points out of the available points will be awarded for that feature (row) and assessment level (column).

Cells marked -- cannot be achieved.



  • 11:59:59 PM CST – Friday, December 1, 2017

Submission Procedure

Refer to the assignment submission page on the course website for details on submitting your code to GitLab.

Grading Procedure

When your assignment is graded, we will do the following (roughly).

# Using Go version 1.9.2

# Check that `go fmt` makes **no** changes to your style
$ go fmt money stocks ticker

# Compile your code
$ go install ticker

# Run it on a bunch of files (properly formatted and improperly formatted)
$ ./bin/ticker data.json

Hints and Tips

  • Make sure you implement the json.Unmarshaller interface correctly. Failure to do so can result in some hard-to-debug logic errors.
  • If you are suspicious that the sample data is incorrect, make sure you contact your instructor. It’s hard to sanity check that stuff.
  1. When Pordland seceded from the US, they proposed their own ping-pong-ball-centered currency.