diff --git a/golang/laba7/cars.go b/golang/laba7/cars.go index 24bebe65..6f4ed012 100644 --- a/golang/laba7/cars.go +++ b/golang/laba7/cars.go @@ -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 } diff --git a/golang/laba7/food.go b/golang/laba7/food.go index 11d72e2d..97d8bc52 100644 --- a/golang/laba7/food.go +++ b/golang/laba7/food.go @@ -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 } diff --git a/golang/laba7/lab7.go b/golang/laba7/lab7.go index f0ebfb0e..43fdf452 100644 --- a/golang/laba7/lab7.go +++ b/golang/laba7/lab7.go @@ -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)) } diff --git a/golang/laba7/product.go b/golang/laba7/product.go index 2d2997d0..70183710 100644 --- a/golang/laba7/product.go +++ b/golang/laba7/product.go @@ -2,6 +2,6 @@ package laba7 type Product interface { ProductInfo() string - applyDiscount(discount float64) - getPrice() float64 + ApplyDiscount(discount float64) + GetPrice() float64 } diff --git a/golang/laba7/technic.go b/golang/laba7/technic.go index 5525791a..c84310ea 100644 --- a/golang/laba7/technic.go +++ b/golang/laba7/technic.go @@ -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 }