diff --git a/main.go b/main.go index b2989a6..b46572c 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,18 @@ import ( */ func main() { + + cage1 := zoo.Cage{Size: "10x10", Color: "green", Number: 1, Animal: zoo.Animal{Kind: "Leon", Name: "Pusic", Number_of_legs: 4, Predator: true}} + cages := []zoo.Cage{cage1, {Size: "20x20", Color: "red", Number: 2, Animal: zoo.Animal{Kind: "mouse", Name: "Miki", Number_of_legs: 4, Predator: false}}} + + leon := zoo.Animal{Kind: "Elephant", Name: "White", Number_of_legs: 4, Predator: false} + cages = append(cages, zoo.Cage{Size: "10x10", Color: "green", Number: 1, Animal: leon}) + fmt.Printf("On duty today: %s, with %d years of experience\n", zoo.Mihalich.Name, zoo.Mihalich.Experience) - fmt.Printf("In the program there is a %s named: %s. It has %d lags", zoo.Spider.Kind, zoo.Spider.Name, zoo.Spider.Number_of_legs) + fmt.Printf("We have a %v cages\n", len(cages)) + for i := 0; i < len(cages); i++ { + fmt.Printf("In cage: %v cages, we have %s, named %s. And ", i+1, cages[i].Animal.Kind, cages[i].Animal.Name) + cages[i].Animal.Food() + } } diff --git a/zoo/zoo.go b/zoo/zoo.go index 3dd0247..d3a33df 100644 --- a/zoo/zoo.go +++ b/zoo/zoo.go @@ -9,17 +9,27 @@ type zookeeper struct { Experience int } -type animal struct { +type Animal struct { Kind string Name string Number_of_legs int + Predator bool } -type cage struct { +type Cage struct { Size string Color string Number int + Animal Animal +} + +func (a *Animal) Food() { + if a.Predator == true { + println("it likes meat") + } else { + println("it likes apple") + } + } var Mihalich = zookeeper{"Mihail", "Ivanov", 56, 30} -var Spider = animal{Kind: "spider", Name: "Gora", Number_of_legs: 8}