1package main23// Definitions related to the Train type45import (6 "fmt"7)89// Train contains all of the information we care about for a single train.10type Train struct {11 Line int12 Cars []int13 Stop string14 Direction int15 Trip string16}1718func IsCarNew(car, line int) bool {19 switch line {20 case Red:21 return car >= 1900 && car <= 215122 case Orange:23 return car >= 1400 && car <= 155124 case GreenB, GreenC, GreenD, GreenE:25 return car >= 3900 && car <= 3924 && car != 392026 default:27 panic("Got LineUnknown in IsNew")28 }29}3031// IsNew returns true if any of the cars in the train are new.32func (t *Train) IsNew() bool {33 for _, car := range t.Cars {34 if IsCarNew(car, t.Line) {35 return true36 }37 }3839 return false40}4142func (t Train) String() string {43 var isnew string44 if t.IsNew() {45 isnew = "is"46 } else {47 isnew = "is not"48 }49 return fmt.Sprintf(50 "%s line train (%v) headed %s at %s. It %s a new train",51 LineToString(t.Line),52 t.Cars,53 DirectionToString(t.Direction),54 t.Stop,55 isnew)56}