A program that prints out data for a set of values.

PHOTO EMBED

Tue Nov 15 2022 16:49:46 GMT+0000 (UTC)

Saved by @Plastikov #go

package main

import (
	"fmt"
)

type Animal struct {
	food, locomotion, sound string
}

func (v Animal) Eat() {
	fmt.Println(v.food)
}

func (v Animal) Move() {
	fmt.Println(v.locomotion)
}

func (v Animal) Speak() {
	fmt.Println(v.sound)
}

func main() {
	m := map[string]Animal{
		"cow" : Animal{"grass","walk","moo"},
		"bird" : Animal{"worms","fly","peep"},
		"snake" : Animal{"mice","slither","hsss"},
	}
	for{
		fmt.Print(">")
		name:=""
		action:=""
		fmt.Scan(&name,&action)
		if action=="eat"{
			m[name].Eat()
		} else if action=="move"{
			m[name].Move()
		} else if action=="speak"{
			m[name].Speak()
		}
	}
}
content_copyCOPY