Created
August 20, 2020 19:19
-
-
Save mkock/71394389da127f7b120e09ede2c34010 to your computer and use it in GitHub Desktop.
Bus Ride, code snippet 21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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