Skip to content

Commit

Permalink
Lab5.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mutil2 authored Dec 28, 2023
1 parent 48006f4 commit ec6a2fb
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions golang/Lab5/Lab5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"errors"
)

type Dog struct {
Name string
Age int
Weight float64
}

func NewDog(dog_name string, dog_age int, dog_weight float64) (Dog, error) {
var d Dog = Dog{Name: dog_name}
err := d.SetAge(dog_age)
if err != nil {
return Dog{}, err
}
err = d.SetWeight(dog_weight)
if err != nil {
return Dog{}, err
}
return d, nil
}

func (d *Dog) SetAge(age int) error {
if age < 0 {
return errors.New("Возраст не может быть отрицательным")
}
d.Age = age
return nil
}

func (d *Dog) SetWeight(weight float64) error {
if weight <= 0 {
return errors.New("Вес не может быть меньше или равен 0")
}
d.Weight = weight
return nil
}

func (d Dog) GetAge() int {
return d.Age
}

func (d Dog) GetWeight() float64 {
return d.Weight
}

0 comments on commit ec6a2fb

Please sign in to comment.