Progress bar

Assignment overview

In this assignment, you will create a professional-looking “progress bar” package, that others can use to add progress bar functionality to their apps. (You may find it useful to use in your own projects!)

Instructions

Create a package called progress. It should expose a type called ProgressBar. Likely, you will choose to use a struct as the underlying type for your progress bar.

The type should have several public methods:

You can add any other methods or functions you’d like, but they should not be public methods (i.e., use lowercase letters).

Testing your code

In a separate folder, create the following program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import "fmt"
import "time"
import "math/rand"
// you will also need to import your package

func main() {
  fmt.Println("Welcome. Now processing items...")

  var pb progress.ProgressBar

  // Say that we have 90 items to process, and keep processing
  // while the progress bar is active.
  pb.Start(90)
  for pb.IsActive() {
    pb.Increment()
    timeToProcess := time.Duration(300+rand.Intn(200)) * time.Millisecond
    time.Sleep(timeToProcess)
  }

  fmt.Println("Finished processing items.")
}

You do not need to upload this main package, just use it to test your program. Upload your progress bar package as YourNameProgressBar.go. You should leave a Google Classroom comment describing how your testing went, and if there are any known bugs.