Skip to content

Commit

Permalink
ispravila
Browse files Browse the repository at this point in the history
  • Loading branch information
Surikenya committed Dec 18, 2024
1 parent ab25cd5 commit cffbc9b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 47 deletions.
16 changes: 8 additions & 8 deletions golang/laba7/cars.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ type Car struct {
brand string
}

func (c *Car) getPrice() float64 {
func (c *Car) GetPrice() float64 {
return c.price
}

func (c *Car) setPrice(newPrice float64) {
func (c *Car) SetPrice(newPrice float64) {
c.price = newPrice
}

func (c *Car) applyDiscount(discount float64) {
func (c *Car) ApplyDiscount(discount float64) {
c.price = (100 - discount) * c.price / 100
}

func (c *Car) getModel() string {
func (c *Car) GetModel() string {
return c.model
}

func (c *Car) getName() string {
func (c *Car) GetName() string {
return c.name
}

func (c *Car) getBrand() string {
func (c *Car) GetBrand() string {
return c.brand
}

func (c *Car) getColor() string {
func (c *Car) GetColor() string {
return c.color
}

func (c *Car) setColor(newName string) {
func (c *Car) SetColor(newName string) {
c.color = newName
}

Expand Down
10 changes: 5 additions & 5 deletions golang/laba7/food.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ type Food struct {
weight float64
}

func (f *Food) getPrice() float64 {
func (f *Food) GetPrice() float64 {
return f.price
}

func (f *Food) setPrice(newPrice float64) {
func (f *Food) SetPrice(newPrice float64) {
f.price = newPrice
}

func (f *Food) getName() string {
func (f *Food) GetName() string {
return f.name
}

func (f *Food) setName(newName string) {
func (f *Food) SetName(newName string) {
f.name = newName
}

func (f *Food) applyDiscount(discount float64) {
func (f *Food) ApplyDiscount(discount float64) {
f.price = (100 - discount) * f.price / 100
}

Expand Down
35 changes: 11 additions & 24 deletions golang/laba7/lab7.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,25 @@ import (
func CalculationSumProduct(listproducts []Product) string {
var sum float64 = 0
for _, product := range listproducts {
sum += product.getPrice()
sum += product.GetPrice()
}
s := fmt.Sprintf("%.2f", sum)
return s
}

func RunLab7() {
bubleTea := &Food{name: "Баблти", price: 149.99, weight: 10}
audi := &Car{price: 1500000, name: "Ауди", color: "Абсолютный черный", model: "А4", brand: "Audi"}
phone := &Technic{price: 2000000, name: "Audi", color: "черный"}
var bubbleTea Product = &Food{name: "Баблти", price: 149.99, weight: 10}
var audi Product = &Car{price: 150000, name: "Ауди", color: "Абсолютный черный", model: "A4", brand: "Audi"}
var phone Product = &Technic{price: 200000, name: "Audi", color: "Черный"}

bubleTea.setName("Бобати")
bubleTea.setPrice(159.99)
bubleTea.getName()
phone.getName()
phone.getPrice()
phone.getColor()
phone.getModel()
phone.setPrice(14000)
phone.getCode()
phone.getBrand()
audi.getName()
audi.setPrice(1600000)
audi.setColor("белый")
audi.getColor()
audi.getBrand()
audi.getModel()
fmt.Println(bubbleTea.ProductInfo())
fmt.Println(audi.ProductInfo())
fmt.Println(phone.ProductInfo())

listproducts := []Product{bubleTea, audi, phone}
listproducts := []Product{bubbleTea, audi, phone}
fmt.Printf("Сумма товаров, без учёта скидки, равна: %v рублей \n", CalculationSumProduct(listproducts))
bubleTea.applyDiscount(9)
audi.applyDiscount(23)
phone.applyDiscount(8)
bubbleTea.ApplyDiscount(9)
audi.ApplyDiscount(23)
phone.ApplyDiscount(8)
fmt.Printf("Сумма товаров, с учётом скидки, равна: %v рублей \n", CalculationSumProduct(listproducts))
}
4 changes: 2 additions & 2 deletions golang/laba7/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package laba7

type Product interface {
ProductInfo() string
applyDiscount(discount float64)
getPrice() float64
ApplyDiscount(discount float64)
GetPrice() float64
}
16 changes: 8 additions & 8 deletions golang/laba7/technic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ type Technic struct {
code float64
}

func (t *Technic) applyDiscount(discount float64) {
func (t *Technic) ApplyDiscount(discount float64) {
t.price = (100 - discount) * t.price / 100
}

func (t *Technic) getPrice() float64 {
func (t *Technic) GetPrice() float64 {
return t.price
}

func (t *Technic) setPrice(newPrice float64) {
func (t *Technic) SetPrice(newPrice float64) {
t.price = newPrice
}

func (t *Technic) getName() string {
func (t *Technic) GetName() string {
return t.name
}

func (t *Technic) getColor() string {
func (t *Technic) GetColor() string {
return t.color
}

func (t *Technic) getModel() string {
func (t *Technic) GetModel() string {
return t.model
}

func (t *Technic) getCode() float64 {
func (t *Technic) GetCode() float64 {
return t.code
}

func (t *Technic) getBrand() string {
func (t *Technic) GetBrand() string {
return t.brand
}

Expand Down

0 comments on commit cffbc9b

Please sign in to comment.