Skip to content

Instantly share code, notes, and snippets.

@mkock
Created August 20, 2020 19:19
Show Gist options
  • Select an option

  • Save mkock/71394389da127f7b120e09ede2c34010 to your computer and use it in GitHub Desktop.

Select an option

Save mkock/71394389da127f7b120e09ede2c34010 to your computer and use it in GitHub Desktop.
Bus Ride, code snippet 21
func main() {
fmt.Println("Starting simulation")
expressLine := busservice.NewBus("Express Line")
s1 := busservice.BusStop{Name: "Downtown"}
s2 := busservice.BusStop{Name: "The University"}
s3 := busservice.BusStop{Name: "The Village"}
expressLine.AddStop(&s1)
expressLine.AddStop(&s2)
expressLine.AddStop(&s3)
john := busservice.Prospect{
SSN:         "12345612-22",
Destination: &s2,
}
betty := busservice.Prospect{
SSN:         "11223322-67",
Destination: &s3,
}
s1.NotifyProspectArrival(john)
s1.NotifyProspectArrival(betty)
for expressLine.Go() {
expressLine.VisitPassengers(func(p busservice.Passenger) {
fmt.Printf("    Passenger with SSN %q is heading to %q\n", p.SSN, p.Destination.Name)
})
}
fmt.Println("Simulation done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment