Skip to content

Commit

Permalink
Исправления: добавил применение скидок через интерфейс и переделал фу…
Browse files Browse the repository at this point in the history
…нкции
  • Loading branch information
Yvelltalik committed Dec 16, 2024
1 parent 5e04964 commit b5e7dcd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
28 changes: 14 additions & 14 deletions golang/lab7/Book.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package lab7

import "fmt"
import (
"fmt"
)

type Book struct {
Name string
Author string
Price float64
}

func (e *Book) SetName(name string) {
e.Name = name
}

func (b *Book) GetName() string {
return b.Name
}

func (b *Book) GetPrice() float64 {
return b.Price
}

func (b *Book) SetPrice(price float64) {
func NewBook(name string, author string, price float64) *Book {
b := new(Book)
b.Name = name
b.Author = author
b.Price = price
return b
}

func (b *Book) SetPrice(price float64) { b.Price = price }
func (b Book) GetPrice() float64 { return b.Price }
func (b *Book) SetName(name string) { b.Name = name }
func (b Book) GetName() string { return b.Name }
func (b *Book) SetAuthor(author string) { b.Author = author }

func (b *Book) ApplyDiscount(discount float64) {
if discount > 0 && discount <= 100 {
b.SetPrice(b.GetPrice() * (1 - discount/100))
Expand Down
22 changes: 10 additions & 12 deletions golang/lab7/Electronics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@ type Electronics struct {
Price float64
}

func (e *Electronics) SetModel(model string) {
func NewElectronics(name string, model string, price float64) *Electronics {
e := new(Electronics)
e.Name = name
e.Model = model
}

func (e *Electronics) GetName() string {
return e.Name
}

func (e *Electronics) GetPrice() float64 {
return e.Price
}

func (e *Electronics) SetPrice(price float64) {
e.Price = price
return e
}

func (e *Electronics) SetPrice(price float64) { e.Price = price }
func (e Electronics) GetPrice() float64 { return e.Price }
func (e *Electronics) SetName(name string) { e.Name = name }
func (e Electronics) GetName() string { return e.Name }
func (e *Electronics) SetModel(model string) { e.Model = model }

func (e *Electronics) ApplyDiscount(discount float64) {
if discount > 0 && discount <= 100 {
e.SetPrice(e.GetPrice() * (1 - discount/100))
Expand Down

0 comments on commit b5e7dcd

Please sign in to comment.