Skip to content

Commit

Permalink
HW04 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Олег Владимирович Евдокимов committed Jan 13, 2024
1 parent aa68d88 commit 94c81ba
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
4 changes: 2 additions & 2 deletions hw04_struct_comparator/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/fixme_my_friend/hw04_struct_comparator
module github.com/es-x/go_basic/hw04_struct_comparator

go 1.20
go 1.20
13 changes: 0 additions & 13 deletions hw04_struct_comparator/go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
39 changes: 38 additions & 1 deletion hw04_struct_comparator/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
package main

import (
"fmt"
)

type book struct {
Id int

Check warning on line 8 in hw04_struct_comparator/main.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: struct field Id should be ID (revive)
Title, Author string
Year, Size int
Rate float32
}

func (p *book) Print() {
fmt.Println("Id:", p.Id)
fmt.Println("Title:", p.Title)
fmt.Println("Author:", p.Author)
fmt.Println("Year:", p.Year)
fmt.Println("Size:", p.Size)
fmt.Println("Rate:", p.Rate)
}

func main() {
// Place your code here.
book1 := &book{1, "skazki", "Pushkin", 1825, 23, 4.3}
book2 := &book{2, "drama", "Lermontov", 1817, 302, 4.6}
book1.Print()
fmt.Println("--------------")
book2.Print()
fmt.Println("--------------")
var s string

fmt.Printf("Введите поле для сравнения Year, Size или Rate: ")
fmt.Scanf("%s", &s)
switch {
case s == "Year" || s == "year":
fmt.Println(book1.Year > book2.Year)
case s == "Size" || s == "size":
fmt.Println(book1.Size > book2.Size)
case s == "Rate" || s == "rate":
fmt.Println(book1.Rate > book2.Rate)
}
}

0 comments on commit 94c81ba

Please sign in to comment.