Skip to content

Commit

Permalink
GO-0001: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Matkovskyi committed Sep 13, 2023
1 parent 69794dc commit 33e1191
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}
16 changes: 13 additions & 3 deletions zoo/zoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 33e1191

Please sign in to comment.