-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cat | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type cat struct { | ||
name string | ||
age uint8 | ||
color string | ||
} | ||
|
||
func NewCat(name_cat string, age_cat uint8, color string) (cat, error) { | ||
var c cat = cat{ | ||
name: name_cat, | ||
} | ||
c.SetColor(color) | ||
var err = c.SetAge(age_cat) | ||
return c, err | ||
} | ||
|
||
func (c *cat) Meow() { | ||
fmt.Printf("%s мяукнул", c.GetName()) | ||
} | ||
|
||
func (c *cat) SetName(name string) { | ||
c.name = name | ||
} | ||
|
||
func (c *cat) SetColor(color string) { | ||
c.color = color | ||
} | ||
|
||
func (c *cat) SetAge(age uint8) error { | ||
if age <= 50 { | ||
c.age = age | ||
return nil | ||
} else { | ||
return fmt.Errorf("Кошки не живут больше 50 лет!") | ||
} | ||
} | ||
|
||
func (c *cat) GetName() string { | ||
return c.name | ||
} | ||
|
||
func (c *cat) GetAge() uint8 { | ||
return c.age | ||
} | ||
|
||
func (c *cat) GetColor() string { | ||
return c.color | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters