Source File: ex22/main.go

package main

import (
    "fmt"
)

type Animal struct {
    Name string
    Age int
    Species string
    Weight float64
}

type Fruit struct {
    Name string
    Taste string
    Smell string
}

func BadPrinter(thing any) {
    switch what := thing.(type) {
        case Animal:
            fmt.Println("-- Animal named", what.Name)
            fmt.Println(what.Name, "is", what.Age, "years old.")
            fmt.Println(what.Name, "is a", what.Species)
            fmt.Println(what.Name, "weighs", what.Weight)
        case Fruit:
            fmt.Println("-- Fruit named", what.Name)
            fmt.Println(what.Name, "tasts like", what.Taste)
            fmt.Println(what.Name, "smells like", what.Smell)
        default:
            fmt.Println("I don't know how to print a", what)
    }
}

func main() {
    joey := Animal{"Joey", 3, "Kangaroo", 100.0}
    BadPrinter(joey)

    durian := Fruit{"Durian", "Heaven", "Dead bodies and onions."}
    BadPrinter(durian)
}