-
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.
Merge pull request #265 from Vladislav3707/Kuzmin_Vladislav_Ivanovich
лаб 5
- Loading branch information
Showing
4 changed files
with
139 additions
and
3 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,15 @@ | ||
{ | ||
// Используйте IntelliSense, чтобы узнать о возможных атрибутах. | ||
// Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов. | ||
// Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch Package", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "${fileDirname}" | ||
} | ||
] | ||
} |
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
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,81 @@ | ||
package lab5 | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
const ( | ||
ErrInvalidWeight = "неверно указан вес мыши, пожалуйста, укажите действительное значение" | ||
ErrInvalidHeight = "неверно указан рост мыши, пожалуйста, укажите действительное значение" | ||
ErrInvalidAge = "неверно указан возраст мыши, пожалуйста, укажите действительное значение" | ||
) | ||
|
||
type Mouse struct { | ||
weight float64 | ||
height float64 | ||
age int | ||
name string | ||
} | ||
|
||
func NewMouse(weight, height float64, age int, name string) (*Mouse, error) { | ||
m := &Mouse{ | ||
weight: weight, | ||
height: height, | ||
age: age, | ||
name: name, | ||
} | ||
if err := m.SetWeight(weight); err != nil { | ||
return nil, err | ||
} | ||
if err := m.SetHeight(height); err != nil { | ||
return nil, err | ||
} | ||
if err := m.SetAge(age); err != nil { | ||
return nil, err | ||
} | ||
return m, nil | ||
} | ||
|
||
func (m *Mouse) GetWeight() float64 { | ||
return m.weight | ||
} | ||
|
||
func (m *Mouse) SetWeight(weight float64) error { | ||
if weight < 0 || weight > 30 { | ||
return errors.New(ErrInvalidWeight) | ||
} | ||
m.weight = weight | ||
return nil | ||
} | ||
|
||
func (m *Mouse) GetHeight() float64 { | ||
return m.height | ||
} | ||
|
||
func (m *Mouse) SetHeight(height float64) error { | ||
if height < 0 || height > 30 { | ||
return errors.New(ErrInvalidHeight) | ||
} | ||
m.height = height | ||
return nil | ||
} | ||
|
||
func (m *Mouse) GetAge() int { | ||
return m.age | ||
} | ||
|
||
func (m *Mouse) SetAge(age int) error { | ||
if age < 0 || age > 50 { | ||
return errors.New(ErrInvalidAge) | ||
} | ||
m.age = age | ||
return nil | ||
} | ||
|
||
func (m *Mouse) GetName() string { | ||
return m.name | ||
} | ||
|
||
func (m *Mouse) SetName(name string) { | ||
m.name = name | ||
} |
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