diff --git a/golang/internal/laba5/laba5.go b/golang/internal/laba5/laba5.go new file mode 100644 index 00000000..fd40837d --- /dev/null +++ b/golang/internal/laba5/laba5.go @@ -0,0 +1,57 @@ +package laba5 +import ( + "errors" +) +type ( + Year int + Killogram int +) +const ( + ErrIncorrectYear = "неправильный возраст" + ErrIncorrectKillogram = "неправильный вес" +) +type Dog struct { + age Year + ves Killogram + poroda string +} +func (d * Dog) SetAge(age Year) error{ + if age >= 0 && age <= 20{ + d.age = age + return nil + } + return errors.New(ErrIncorrectYear) +} +func (d * Dog) SetVes(ves Killogram) error{ + if ves >= 5 && ves <= 65{ + d.ves = ves + return nil + } + return errors.New(ErrIncorrectKillogram) +} +func (d * Dog) SetPoroda(poroda string){ + d.poroda = poroda +} +func (d Dog) GetAge() Year{ + return d.age +} +func (d Dog) GetVes() Killogram{ + return d.ves +} +func (d Dog) GetPoroda() string{ + return d.poroda +} +func NewDog(age Year, ves Killogram, poroda string)(*Dog, error){ + tmp := &Dog{ + age: age, + ves : ves, + poroda: poroda, + } + if err := tmp.SetAge(age); err != nil{ + return nil, err + } + if err := tmp.SetVes(ves); err != nil{ + return nil, err + } + return tmp, nil +} \ No newline at end of file diff --git a/golang/main.go b/golang/main.go index 1162421d..a63f33e8 100644 --- a/golang/main.go +++ b/golang/main.go @@ -4,10 +4,19 @@ import ( "fmt" "isuct.ru/informatics2022/internal/laba4" + "isuct.ru/informatics2022/internal/laba5" ) func main() { fmt.Println("Яковлева Алёна") + dog, err := laba5.NewDog(20, 65, "Овчарка") + if err == nil { + fmt.Printf("Dog age is %d\n", dog.GetAge()) + fmt.Printf("Dog ves is %d\n", dog.GetVes()) + fmt.Printf("Dog poroda is %s\n", dog.GetPoroda()) + }else{ + fmt.Println(err) + } y1 := laba4.Task1(0.22, 0.92, 0.14) y2 := laba4.Task2([]float64{0.1, 0.35, 0.4, 0.55, 0.6}) fmt.Println(y1)