From 3b015196a0862e221b626ffe4f3a49e368d3f4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D0=BB=D0=B4=D0=B8=D0=BD=D0=B0=20=D0=94=D0=B0?= =?UTF-8?q?=D1=80=D1=8C=D1=8F?= Date: Mon, 2 Dec 2024 20:17:29 +0300 Subject: [PATCH 1/5] Baldina Lab7 --- golang/Lab7/Lab7.go | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 golang/Lab7/Lab7.go diff --git a/golang/Lab7/Lab7.go b/golang/Lab7/Lab7.go new file mode 100644 index 00000000..432abd15 --- /dev/null +++ b/golang/Lab7/Lab7.go @@ -0,0 +1,65 @@ +package Lab7 + +import ( + "fmt" +) + +type Product interface { + GetName() string + GetPrice() float64 + SetPrice(price float64) + ApplyDiscount(discount float64) +} + +type Item struct { + Name string + Price float64 +} + +func (i *Item) GetName() string { + return i.Name +} + +func (i *Item) GetPrice() float64 { + return i.Price +} + +func (i *Item) SetPrice(price float64) { + i.Price = price +} + +func (i *Item) ApplyDiscount(discount float64) { + i.Price -= discount + if i.Price < 0 { + i.Price = 0 + } +} + +func CalculateTotal(products []Product) float64 { + total := 0.0 + for _, product := range products { + total += product.GetPrice() + } + return total +} + +func RunLab7() { + + item1 := &Item{Name: "Утюг", Price: 1000.0} + item2 := &Item{Name: "Микроволновка", Price: 1500.0} + item3 := &Item{Name: "Холодильник", Price: 3000.0} + + item1.ApplyDiscount(100) + item2.ApplyDiscount(50) + + products := []Product{item1, item2, item3} + + fmt.Printf("Общая стоимость без учёта скидок: %.2f\n", CalculateTotal([]Product{ + &Item{Name: "Утюг", Price: 1000.0}, + &Item{Name: "Микроволновка", Price: 1500.0}, + &Item{Name: "Холодильник", Price: 3000.0}, + })) + + totalAfterDiscounts := CalculateTotal(products) + fmt.Printf("Общая стоимость с учётом скидок: %.2f\n", totalAfterDiscounts) +} From 739a9fb3a0fbae9be8262c4ca1ec154beba0c87a Mon Sep 17 00:00:00 2001 From: BaldinaDaria Date: Mon, 2 Dec 2024 20:22:04 +0300 Subject: [PATCH 2/5] Update Lab7.go --- golang/Lab7/Lab7.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/golang/Lab7/Lab7.go b/golang/Lab7/Lab7.go index 432abd15..dbcffe82 100644 --- a/golang/Lab7/Lab7.go +++ b/golang/Lab7/Lab7.go @@ -43,8 +43,7 @@ func CalculateTotal(products []Product) float64 { return total } -func RunLab7() { - +func RunLab7() { item1 := &Item{Name: "Утюг", Price: 1000.0} item2 := &Item{Name: "Микроволновка", Price: 1500.0} item3 := &Item{Name: "Холодильник", Price: 3000.0} From 26b170c41f643bfe299dff1b2eee8e0e9339d139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D0=BB=D0=B4=D0=B8=D0=BD=D0=B0=20=D0=94=D0=B0?= =?UTF-8?q?=D1=80=D1=8C=D1=8F?= Date: Wed, 18 Dec 2024 19:43:52 +0300 Subject: [PATCH 3/5] Baldina Lab7 --- golang/Lab7/Lab7.go | 42 ++++++++++--------------------------- golang/Lab7/iron.go | 5 +++++ golang/Lab7/microwave.go | 5 +++++ golang/Lab7/product.go | 25 ++++++++++++++++++++++ golang/Lab7/refrigerator.go | 5 +++++ 5 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 golang/Lab7/iron.go create mode 100644 golang/Lab7/microwave.go create mode 100644 golang/Lab7/product.go create mode 100644 golang/Lab7/refrigerator.go diff --git a/golang/Lab7/Lab7.go b/golang/Lab7/Lab7.go index dbcffe82..214ea209 100644 --- a/golang/Lab7/Lab7.go +++ b/golang/Lab7/Lab7.go @@ -11,30 +11,6 @@ type Product interface { ApplyDiscount(discount float64) } -type Item struct { - Name string - Price float64 -} - -func (i *Item) GetName() string { - return i.Name -} - -func (i *Item) GetPrice() float64 { - return i.Price -} - -func (i *Item) SetPrice(price float64) { - i.Price = price -} - -func (i *Item) ApplyDiscount(discount float64) { - i.Price -= discount - if i.Price < 0 { - i.Price = 0 - } -} - func CalculateTotal(products []Product) float64 { total := 0.0 for _, product := range products { @@ -43,10 +19,10 @@ func CalculateTotal(products []Product) float64 { return total } -func RunLab7() { - item1 := &Item{Name: "Утюг", Price: 1000.0} - item2 := &Item{Name: "Микроволновка", Price: 1500.0} - item3 := &Item{Name: "Холодильник", Price: 3000.0} +func RunLab7() { + item1 := &Iron{Item: Item{Name: "Утюг", Price: 1000.0}} + item2 := &Microwave{Item: Item{Name: "Микроволновка", Price: 1500.0}} + item3 := &Refrigerator{Item: Item{Name: "Холодильник", Price: 3000.0}} item1.ApplyDiscount(100) item2.ApplyDiscount(50) @@ -54,11 +30,15 @@ func RunLab7() { products := []Product{item1, item2, item3} fmt.Printf("Общая стоимость без учёта скидок: %.2f\n", CalculateTotal([]Product{ - &Item{Name: "Утюг", Price: 1000.0}, - &Item{Name: "Микроволновка", Price: 1500.0}, - &Item{Name: "Холодильник", Price: 3000.0}, + &Iron{Item: Item{Name: "Утюг", Price: 1000.0}}, + &Microwave{Item: Item{Name: "Микроволновка", Price: 1500.0}}, + &Refrigerator{Item: Item{Name: "Холодильник", Price: 3000.0}}, })) totalAfterDiscounts := CalculateTotal(products) fmt.Printf("Общая стоимость с учётом скидок: %.2f\n", totalAfterDiscounts) } + +func main() { + RunLab7() +} diff --git a/golang/Lab7/iron.go b/golang/Lab7/iron.go new file mode 100644 index 00000000..baf53218 --- /dev/null +++ b/golang/Lab7/iron.go @@ -0,0 +1,5 @@ +package Lab7 + +type Iron struct { + Item +} diff --git a/golang/Lab7/microwave.go b/golang/Lab7/microwave.go new file mode 100644 index 00000000..7adae726 --- /dev/null +++ b/golang/Lab7/microwave.go @@ -0,0 +1,5 @@ +package Lab7 + +type Microwave struct { + Item +} diff --git a/golang/Lab7/product.go b/golang/Lab7/product.go new file mode 100644 index 00000000..a077b3b0 --- /dev/null +++ b/golang/Lab7/product.go @@ -0,0 +1,25 @@ +package Lab7 + +type Item struct { + Name string + Price float64 +} + +func (i *Item) GetName() string { + return i.Name +} + +func (i *Item) GetPrice() float64 { + return i.Price +} + +func (i *Item) SetPrice(price float64) { + i.Price = price +} + +func (i *Item) ApplyDiscount(discount float64) { + i.Price -= discount + if i.Price < 0 { + i.Price = 0 + } +} diff --git a/golang/Lab7/refrigerator.go b/golang/Lab7/refrigerator.go new file mode 100644 index 00000000..2100238a --- /dev/null +++ b/golang/Lab7/refrigerator.go @@ -0,0 +1,5 @@ +package Lab7 + +type Refrigerator struct { + Item +} From 5eb7b9fdce9347779299bb9407233549aa72a7f4 Mon Sep 17 00:00:00 2001 From: BaldinaDaria Date: Wed, 18 Dec 2024 19:47:58 +0300 Subject: [PATCH 4/5] Update Lab7.go --- golang/Lab7/Lab7.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golang/Lab7/Lab7.go b/golang/Lab7/Lab7.go index 214ea209..e3d7027f 100644 --- a/golang/Lab7/Lab7.go +++ b/golang/Lab7/Lab7.go @@ -39,6 +39,6 @@ func RunLab7() { fmt.Printf("Общая стоимость с учётом скидок: %.2f\n", totalAfterDiscounts) } -func main() { +func RunLab7() { RunLab7() } From 6dfe758ad64e023624257f7508afe3e2038f174a Mon Sep 17 00:00:00 2001 From: BaldinaDaria Date: Wed, 18 Dec 2024 19:49:59 +0300 Subject: [PATCH 5/5] Update Lab7.go --- golang/Lab7/Lab7.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golang/Lab7/Lab7.go b/golang/Lab7/Lab7.go index e3d7027f..cf7cb245 100644 --- a/golang/Lab7/Lab7.go +++ b/golang/Lab7/Lab7.go @@ -19,7 +19,7 @@ func CalculateTotal(products []Product) float64 { return total } -func RunLab7() { +func RunLab7A() { item1 := &Iron{Item: Item{Name: "Утюг", Price: 1000.0}} item2 := &Microwave{Item: Item{Name: "Микроволновка", Price: 1500.0}} item3 := &Refrigerator{Item: Item{Name: "Холодильник", Price: 3000.0}}