From a7183ddc1ad31e201fbf30bf176c3e5bf77611a9 Mon Sep 17 00:00:00 2001 From: Vladimir Bes Date: Mon, 17 Feb 2020 00:28:51 +1000 Subject: [PATCH 1/6] lesson-1 --- lesson_1/.keep | 0 .../Contents.swift | 61 +++++++++++++++++++ .../contents.xcplayground | 4 ++ 3 files changed, 65 insertions(+) create mode 100644 lesson_1/.keep create mode 100644 lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift create mode 100644 lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground diff --git a/lesson_1/.keep b/lesson_1/.keep new file mode 100644 index 0000000..e69de29 diff --git a/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift b/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift new file mode 100644 index 0000000..6594e52 --- /dev/null +++ b/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift @@ -0,0 +1,61 @@ +import UIKit + +// +// 1. Решить квадратное уравнение. +let a:Int = 1 +var b:Int = 12 +let c:Int = 36 + +// b в квадрате +let pw:Int = Int(pow(Double(b), 2)) +//Дискриминант +let d:Int = pw - 4 * a * c +if d > 0 { + // корень b^2 - 4ac + let sqr:Int = Int(sqrt(Double(pw - (4 * a * c)))) + + let x1 = (-(b) + sqr) / 2 * a + let x2 = (-(b) - sqr) / 2 * a + print("Уравнение имеет два корня") + print("x1: " + String(x1)) + print("x2: " + String(x2)) +}else if d == 0 { + let sqr:Int = Int(sqrt(Double(pw - (4 * a * c)))) + + let x1 = (-(b) + sqr) / 2 * a + + print("уравнение имеет один корень") + print("x1: " + String(x1)) + +}else { + print("Нет действительных корней") +} + +// 2. Даны катеты прямоугольного треугольника. Найти площадь, периметр и гипотенузу треугольника. +// Катет А +let katetA = 3 +// Катет B +let katetB = 4 +// Площадь +let area = (1 * katetA * katetB) / 2 +print("Площадь: " + String(area)) +//Гипотенуза +let powA = Int(pow(Double(katetA), 2)) +let powB = Int(pow(Double(katetB), 2)) +let gipot = Int(sqrt(Double(powA + powB))) +print("Гипотенуза: " + String(gipot)) +// Периметр +let perim = katetA + katetB + gipot +print("Периметр: " + String(perim)) + + +// 3. * Пользователь вводит сумму вклада в банк и годовой процент. Найти сумму вклада через 5 лет. + +let deposit:Int = 100000 +let percent:Float = 0.14 +var sum = Float(deposit) +for _ in 1...5 { + sum += sum * percent +} +var total = Int(sum) +print("Сумма после 5 лет: " + String(total)) diff --git a/lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground b/lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground new file mode 100644 index 0000000..5da2641 --- /dev/null +++ b/lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From aaf1601c9cbf72b1ba8ac031fcc3a3574b0e3f05 Mon Sep 17 00:00:00 2001 From: Vladimir Bes Date: Wed, 19 Feb 2020 21:33:25 +1000 Subject: [PATCH 2/6] lesson-2 --- .../Contents.swift | 61 ------------- {lesson_1 => lesson_2}/.keep | 0 .../Contents.swift | 90 +++++++++++++++++++ .../contents.xcplayground | 0 4 files changed, 90 insertions(+), 61 deletions(-) delete mode 100644 lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift rename {lesson_1 => lesson_2}/.keep (100%) create mode 100644 lesson_2/2lesson_BesedinVladimir.playground/Contents.swift rename {lesson_1/1Iesson_BesedinVladimir.playground => lesson_2/2lesson_BesedinVladimir.playground}/contents.xcplayground (100%) diff --git a/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift b/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift deleted file mode 100644 index 6594e52..0000000 --- a/lesson_1/1Iesson_BesedinVladimir.playground/Contents.swift +++ /dev/null @@ -1,61 +0,0 @@ -import UIKit - -// -// 1. Решить квадратное уравнение. -let a:Int = 1 -var b:Int = 12 -let c:Int = 36 - -// b в квадрате -let pw:Int = Int(pow(Double(b), 2)) -//Дискриминант -let d:Int = pw - 4 * a * c -if d > 0 { - // корень b^2 - 4ac - let sqr:Int = Int(sqrt(Double(pw - (4 * a * c)))) - - let x1 = (-(b) + sqr) / 2 * a - let x2 = (-(b) - sqr) / 2 * a - print("Уравнение имеет два корня") - print("x1: " + String(x1)) - print("x2: " + String(x2)) -}else if d == 0 { - let sqr:Int = Int(sqrt(Double(pw - (4 * a * c)))) - - let x1 = (-(b) + sqr) / 2 * a - - print("уравнение имеет один корень") - print("x1: " + String(x1)) - -}else { - print("Нет действительных корней") -} - -// 2. Даны катеты прямоугольного треугольника. Найти площадь, периметр и гипотенузу треугольника. -// Катет А -let katetA = 3 -// Катет B -let katetB = 4 -// Площадь -let area = (1 * katetA * katetB) / 2 -print("Площадь: " + String(area)) -//Гипотенуза -let powA = Int(pow(Double(katetA), 2)) -let powB = Int(pow(Double(katetB), 2)) -let gipot = Int(sqrt(Double(powA + powB))) -print("Гипотенуза: " + String(gipot)) -// Периметр -let perim = katetA + katetB + gipot -print("Периметр: " + String(perim)) - - -// 3. * Пользователь вводит сумму вклада в банк и годовой процент. Найти сумму вклада через 5 лет. - -let deposit:Int = 100000 -let percent:Float = 0.14 -var sum = Float(deposit) -for _ in 1...5 { - sum += sum * percent -} -var total = Int(sum) -print("Сумма после 5 лет: " + String(total)) diff --git a/lesson_1/.keep b/lesson_2/.keep similarity index 100% rename from lesson_1/.keep rename to lesson_2/.keep diff --git a/lesson_2/2lesson_BesedinVladimir.playground/Contents.swift b/lesson_2/2lesson_BesedinVladimir.playground/Contents.swift new file mode 100644 index 0000000..fdb75ce --- /dev/null +++ b/lesson_2/2lesson_BesedinVladimir.playground/Contents.swift @@ -0,0 +1,90 @@ +import UIKit + + +//1. Написать функцию, которая определяет, четное число или нет. +func even (_ x:Int) -> Bool { + return x % 2 == 0 +} +even(-2) + +// 2. Написать функцию, которая определяет, делится ли число без остатка на 3. +func residue (_ x:Int) -> Bool { + return x % 3 == 0 +} +residue(-99) + +// 3. Создать возрастающий массив из 100 чисел. + +var massive : [Int] = [] + +for i in 1...100 { + massive.append(i) +} +// 4. Удалить из этого массива все четные числа и все числа, которые не делятся на 3. + +for (_, value) in massive.enumerated() { + if even(value) || residue(value) == true { + massive.remove(at: massive.firstIndex(of: value) ?? 0) + } +} + +//5. * Написать функцию, которая добавляет в массив новое число Фибоначчи, и добавить при помощи нее 100 элементов. +var fibMassive: [Decimal] = [] + +func fib(_ n: Int) { + if n == 0 {fibMassive.append(0)} + if n <= 2 {fibMassive.append(1)} + if n > 2{ + var x:Decimal = 1 + var y:Decimal = 1 + var ans:Decimal = 0 + var i = 2 + while i < n { + ans = x + y + x = y + y = ans + i += 1 + } + fibMassive.append(ans) + } +} +for i in 1...100 { + fib(i) +} +// рекурсией не вывозит это норм? так и должно быть? + + +//6.* Заполнить массив из 100 элементов различными простыми числами. Натуральное число, большее единицы, называется простым, если оно делится только на себя и на единицу. +//a +var simpleMassive: [Int] = [] + +func addMassive (_ n:Int) { + var testMassive: [Int] = [] + for i in 2...n { + let count = 2...i + for j in count{ + if i % j == 0 { + testMassive.append(i) + } + }; + if testMassive.count > 1 { + testMassive.removeAll() + }else{ + testMassive.removeAll() + simpleMassive.append(i) + } + } +} + +addMassive(550) +print(simpleMassive) +//b +let p = simpleMassive.first +//с Не понял что значит зачеркнуть??? + + + + + + + diff --git a/lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground b/lesson_2/2lesson_BesedinVladimir.playground/contents.xcplayground similarity index 100% rename from lesson_1/1Iesson_BesedinVladimir.playground/contents.xcplayground rename to lesson_2/2lesson_BesedinVladimir.playground/contents.xcplayground From 2e5139cadac57e3e08d5f4e82f2cb724116ad070 Mon Sep 17 00:00:00 2001 From: Vladimir Bes Date: Mon, 24 Feb 2020 21:53:06 +1000 Subject: [PATCH 3/6] lesson-3 --- lesson_2/.keep | 0 .../Contents.swift | 90 ---------- .../Contents.swift | 156 ++++++++++++++++++ .../contents.xcplayground | 0 4 files changed, 156 insertions(+), 90 deletions(-) delete mode 100644 lesson_2/.keep delete mode 100644 lesson_2/2lesson_BesedinVladimir.playground/Contents.swift create mode 100644 lesson_3/3lesson_BesedinVladimir.playground/Contents.swift rename {lesson_2/2lesson_BesedinVladimir.playground => lesson_3/3lesson_BesedinVladimir.playground}/contents.xcplayground (100%) diff --git a/lesson_2/.keep b/lesson_2/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/lesson_2/2lesson_BesedinVladimir.playground/Contents.swift b/lesson_2/2lesson_BesedinVladimir.playground/Contents.swift deleted file mode 100644 index fdb75ce..0000000 --- a/lesson_2/2lesson_BesedinVladimir.playground/Contents.swift +++ /dev/null @@ -1,90 +0,0 @@ -import UIKit - - -//1. Написать функцию, которая определяет, четное число или нет. -func even (_ x:Int) -> Bool { - return x % 2 == 0 -} -even(-2) - -// 2. Написать функцию, которая определяет, делится ли число без остатка на 3. -func residue (_ x:Int) -> Bool { - return x % 3 == 0 -} -residue(-99) - -// 3. Создать возрастающий массив из 100 чисел. - -var massive : [Int] = [] - -for i in 1...100 { - massive.append(i) -} -// 4. Удалить из этого массива все четные числа и все числа, которые не делятся на 3. - -for (_, value) in massive.enumerated() { - if even(value) || residue(value) == true { - massive.remove(at: massive.firstIndex(of: value) ?? 0) - } -} - -//5. * Написать функцию, которая добавляет в массив новое число Фибоначчи, и добавить при помощи нее 100 элементов. -var fibMassive: [Decimal] = [] - -func fib(_ n: Int) { - if n == 0 {fibMassive.append(0)} - if n <= 2 {fibMassive.append(1)} - if n > 2{ - var x:Decimal = 1 - var y:Decimal = 1 - var ans:Decimal = 0 - var i = 2 - while i < n { - ans = x + y - x = y - y = ans - i += 1 - } - fibMassive.append(ans) - } -} -for i in 1...100 { - fib(i) -} -// рекурсией не вывозит это норм? так и должно быть? - - -//6.* Заполнить массив из 100 элементов различными простыми числами. Натуральное число, большее единицы, называется простым, если оно делится только на себя и на единицу. -//a -var simpleMassive: [Int] = [] - -func addMassive (_ n:Int) { - var testMassive: [Int] = [] - for i in 2...n { - let count = 2...i - for j in count{ - if i % j == 0 { - testMassive.append(i) - } - }; - if testMassive.count > 1 { - testMassive.removeAll() - }else{ - testMassive.removeAll() - simpleMassive.append(i) - } - } -} - -addMassive(550) -print(simpleMassive) -//b -let p = simpleMassive.first -//с Не понял что значит зачеркнуть??? - - - - - - - diff --git a/lesson_3/3lesson_BesedinVladimir.playground/Contents.swift b/lesson_3/3lesson_BesedinVladimir.playground/Contents.swift new file mode 100644 index 0000000..53f90fd --- /dev/null +++ b/lesson_3/3lesson_BesedinVladimir.playground/Contents.swift @@ -0,0 +1,156 @@ +import UIKit + +enum BrandеTruck: String { + case KAMAZ = "КАМАЗ" + case MAN = "MAN" + case HYUNDAI = "Hyundai" + case MERCEDES = "Mercedes" +} +enum BrandСar: String{ + case HONDA = "Honda" + case LADA = "Lada" + case CITROEN = "Citroen" + case NISSAN = "Nissan" +} +enum Engine { + case start + case stop +} +enum Windows { + case open + case close +} +enum Volume{ + case load(volume:Int) + case unload(volume:Int) +} + +struct Truck { + var brand: BrandеTruck + var model: String + var year: Int //Год выппуска + var stateEngine: Engine //Состояние двигателя + var stateWindows: Windows //Состояние окон + var fullVolume: Int //Объем + var loadVolume: Volume //Значение загрузить/разгрузить + + var freePlace: Int = 0{ + willSet{ + print("Будет изменен груз кузова на: \(newValue)" ) + }didSet{ + print("Был изменен груз кузова с на \(freePlace)") + } + } + + + init(brand: BrandеTruck, model: String, year: Int, stateEngine: Engine = .stop, stateWindows: Windows = .close, fullVolume: Int, loadVolume: Volume = .load(volume: 0)) { + self.brand = brand + self.model = model + self.year = year + self.stateEngine = stateEngine + self.stateWindows = stateWindows + self.fullVolume = fullVolume + self.loadVolume = loadVolume + } + + + mutating func changePlaceVolume() { + let changeVolume = loadVolume + switch changeVolume { + case .load(let volume): + freePlace += volume + case .unload(let volume): + freePlace -= volume + } + } + + + mutating func changeStatusEngine() { + if stateEngine == .stop{ + self.stateEngine = .start + }else{ + self.stateEngine = .stop + } + } +} + +struct Car { + var brand: BrandСar + var model: String + var year: Int //Год выпуска + var stateEngine: Engine //Состояние двигателя + var stateWindows: Windows //Состояние окон + var fullVolume: Int //Обьем кузова + var loadVolume: Volume //Значение загрузить/разгрузить + var freePlace: Int = 0{ + willSet{ + print("Будет изменена загруженность багажника на \(newValue)") + }didSet{ + print("Груз багажника \(freePlace)") + } + } + + init(brand: BrandСar, model: String, year: Int, stateEngine: Engine = .stop, stateWindows: Windows = .close, fullVolume: Int, loadVolume: Volume = .load(volume: 0)) { + self.brand = brand + self.model = model + self.year = year + self.stateEngine = stateEngine + self.stateWindows = stateWindows + self.fullVolume = fullVolume + self.loadVolume = loadVolume + } + + + mutating func changePlaceVolume() { + let changeVolume = loadVolume + switch changeVolume { + case .load(let volume): + freePlace += volume + case .unload(let volume): + freePlace -= volume + } + } + + + mutating func changeStatusWindows() { + if stateWindows == .close{ + self.stateWindows = .open + }else{ + self.stateWindows = .close + } + } +} + +var car = Car(brand: .CITROEN, model: "C4", year: 1997, stateEngine: .stop, stateWindows: .close, fullVolume: 100) +var carTruck = Truck(brand: .MERCEDES, model: "666", year: 1999, stateEngine: .start, stateWindows: .close, fullVolume: 100) + + +var newTruck = Truck(brand: .MAN, model: "555", year: 2005, fullVolume: 300) +var newCar = Car(brand: .NISSAN, model: "Terrano", year: 2000, fullVolume: 100) + + + +//Именение свойств +newTruck.model = "222" +newTruck.fullVolume = 500 +newTruck.changeStatusEngine() +newTruck.year = 3000 + +newTruck.loadVolume = .load(volume: 200) +newTruck.changePlaceVolume() +newTruck.loadVolume = .load(volume: 200) +newTruck.changePlaceVolume() + + +newCar.changeStatusWindows() +newCar.loadVolume = .load(volume: 20) +newCar.changePlaceVolume() +newCar.loadVolume = .load(volume: 40) +newCar.changePlaceVolume() +newCar.loadVolume = .unload(volume: 30) +newCar.changePlaceVolume() + +print("\\\\\\") +print(newTruck.brand, newTruck.model, newTruck.year, newTruck.stateEngine, newTruck.stateWindows, newTruck.fullVolume, newTruck.freePlace) +print(newCar.brand, newCar.model, newTruck.year, newCar.stateEngine, newCar.stateWindows, newCar.fullVolume, newCar.freePlace) + diff --git a/lesson_2/2lesson_BesedinVladimir.playground/contents.xcplayground b/lesson_3/3lesson_BesedinVladimir.playground/contents.xcplayground similarity index 100% rename from lesson_2/2lesson_BesedinVladimir.playground/contents.xcplayground rename to lesson_3/3lesson_BesedinVladimir.playground/contents.xcplayground From 15d1c9c902d259d7538c4eed8164d0140d97f4c0 Mon Sep 17 00:00:00 2001 From: Vladimir Bes Date: Wed, 26 Feb 2020 23:00:18 +1000 Subject: [PATCH 4/6] lesson-04 --- .../Contents.swift | 156 ------------------ .../Contents.swift | 134 +++++++++++++++ .../contents.xcplayground | 0 3 files changed, 134 insertions(+), 156 deletions(-) delete mode 100644 lesson_3/3lesson_BesedinVladimir.playground/Contents.swift create mode 100644 lesson_4/4lesson_BesedinVladimir.playground/Contents.swift rename {lesson_3/3lesson_BesedinVladimir.playground => lesson_4/4lesson_BesedinVladimir.playground}/contents.xcplayground (100%) diff --git a/lesson_3/3lesson_BesedinVladimir.playground/Contents.swift b/lesson_3/3lesson_BesedinVladimir.playground/Contents.swift deleted file mode 100644 index 53f90fd..0000000 --- a/lesson_3/3lesson_BesedinVladimir.playground/Contents.swift +++ /dev/null @@ -1,156 +0,0 @@ -import UIKit - -enum BrandеTruck: String { - case KAMAZ = "КАМАЗ" - case MAN = "MAN" - case HYUNDAI = "Hyundai" - case MERCEDES = "Mercedes" -} -enum BrandСar: String{ - case HONDA = "Honda" - case LADA = "Lada" - case CITROEN = "Citroen" - case NISSAN = "Nissan" -} -enum Engine { - case start - case stop -} -enum Windows { - case open - case close -} -enum Volume{ - case load(volume:Int) - case unload(volume:Int) -} - -struct Truck { - var brand: BrandеTruck - var model: String - var year: Int //Год выппуска - var stateEngine: Engine //Состояние двигателя - var stateWindows: Windows //Состояние окон - var fullVolume: Int //Объем - var loadVolume: Volume //Значение загрузить/разгрузить - - var freePlace: Int = 0{ - willSet{ - print("Будет изменен груз кузова на: \(newValue)" ) - }didSet{ - print("Был изменен груз кузова с на \(freePlace)") - } - } - - - init(brand: BrandеTruck, model: String, year: Int, stateEngine: Engine = .stop, stateWindows: Windows = .close, fullVolume: Int, loadVolume: Volume = .load(volume: 0)) { - self.brand = brand - self.model = model - self.year = year - self.stateEngine = stateEngine - self.stateWindows = stateWindows - self.fullVolume = fullVolume - self.loadVolume = loadVolume - } - - - mutating func changePlaceVolume() { - let changeVolume = loadVolume - switch changeVolume { - case .load(let volume): - freePlace += volume - case .unload(let volume): - freePlace -= volume - } - } - - - mutating func changeStatusEngine() { - if stateEngine == .stop{ - self.stateEngine = .start - }else{ - self.stateEngine = .stop - } - } -} - -struct Car { - var brand: BrandСar - var model: String - var year: Int //Год выпуска - var stateEngine: Engine //Состояние двигателя - var stateWindows: Windows //Состояние окон - var fullVolume: Int //Обьем кузова - var loadVolume: Volume //Значение загрузить/разгрузить - var freePlace: Int = 0{ - willSet{ - print("Будет изменена загруженность багажника на \(newValue)") - }didSet{ - print("Груз багажника \(freePlace)") - } - } - - init(brand: BrandСar, model: String, year: Int, stateEngine: Engine = .stop, stateWindows: Windows = .close, fullVolume: Int, loadVolume: Volume = .load(volume: 0)) { - self.brand = brand - self.model = model - self.year = year - self.stateEngine = stateEngine - self.stateWindows = stateWindows - self.fullVolume = fullVolume - self.loadVolume = loadVolume - } - - - mutating func changePlaceVolume() { - let changeVolume = loadVolume - switch changeVolume { - case .load(let volume): - freePlace += volume - case .unload(let volume): - freePlace -= volume - } - } - - - mutating func changeStatusWindows() { - if stateWindows == .close{ - self.stateWindows = .open - }else{ - self.stateWindows = .close - } - } -} - -var car = Car(brand: .CITROEN, model: "C4", year: 1997, stateEngine: .stop, stateWindows: .close, fullVolume: 100) -var carTruck = Truck(brand: .MERCEDES, model: "666", year: 1999, stateEngine: .start, stateWindows: .close, fullVolume: 100) - - -var newTruck = Truck(brand: .MAN, model: "555", year: 2005, fullVolume: 300) -var newCar = Car(brand: .NISSAN, model: "Terrano", year: 2000, fullVolume: 100) - - - -//Именение свойств -newTruck.model = "222" -newTruck.fullVolume = 500 -newTruck.changeStatusEngine() -newTruck.year = 3000 - -newTruck.loadVolume = .load(volume: 200) -newTruck.changePlaceVolume() -newTruck.loadVolume = .load(volume: 200) -newTruck.changePlaceVolume() - - -newCar.changeStatusWindows() -newCar.loadVolume = .load(volume: 20) -newCar.changePlaceVolume() -newCar.loadVolume = .load(volume: 40) -newCar.changePlaceVolume() -newCar.loadVolume = .unload(volume: 30) -newCar.changePlaceVolume() - -print("\\\\\\") -print(newTruck.brand, newTruck.model, newTruck.year, newTruck.stateEngine, newTruck.stateWindows, newTruck.fullVolume, newTruck.freePlace) -print(newCar.brand, newCar.model, newTruck.year, newCar.stateEngine, newCar.stateWindows, newCar.fullVolume, newCar.freePlace) - diff --git a/lesson_4/4lesson_BesedinVladimir.playground/Contents.swift b/lesson_4/4lesson_BesedinVladimir.playground/Contents.swift new file mode 100644 index 0000000..0fd1a38 --- /dev/null +++ b/lesson_4/4lesson_BesedinVladimir.playground/Contents.swift @@ -0,0 +1,134 @@ +import UIKit + +enum BrandsSportСar: String{ + case McLaren = "McLaren" + case AstonMartin = "Aston Martin" + case Lamborghini = "Lamborghini" + case Ferrari = "Ferrari" +} +enum BrandsCarTruck: String { + case KAMAZ = "КАМАЗ" + case MAN = "MAN" + case HYUNDAI = "Hyundai" + case MERCEDES = "Mercedes" +} + +enum ColorsCars: String { + case yellow = "Желтый" + case red = "Красный" + case black = "Черный" + case purple = "Фиолетовый" +} +enum StateEngine { + case start + case stop +} + +class Car { + let color:ColorsCars + let model:String + var statusEngine:StateEngine + init(model: String ,color: ColorsCars, statusEngine:StateEngine) { + self.model = model + self.color = color + self.statusEngine = statusEngine + } + + func changeStatusEngine () { + + } +} + +class SportCar: Car { + + enum ModsSportCar { + case drift + case sprint + } + + let brand:BrandsSportСar + var maxSpeed: Int + var modif: ModsSportCar + + init(brand: BrandsSportСar, + model: String, + maxSpeed: Int, + color: ColorsCars, + statusEngine: StateEngine = .stop, + modif: ModsSportCar) { + self.brand = brand + self.maxSpeed = maxSpeed + self.modif = modif + super.init(model: model, color: color, statusEngine: statusEngine) + } + + override func changeStatusEngine() { + if statusEngine == .stop{ + self.statusEngine = .start + }else { + self.statusEngine = .stop + } + } + + func changeMod() { + if modif == .sprint{ + self.modif = .drift + }else { + self.modif = .sprint + } + } +} + +class TruckCar: Car { + enum HookTruckCar { + case hook + case unhook + } + + let brand: BrandsCarTruck + let maxTraction: Int + var statusHook: HookTruckCar + + init(brand: BrandsCarTruck, + model: String, + maxTraction: Int, + color: ColorsCars, + statusEngine: StateEngine = .stop, + statusHook: HookTruckCar = .unhook) { + self.brand = brand + self.maxTraction = maxTraction + self.statusHook = statusHook + + super.init(model: model, color: color, statusEngine: statusEngine) + } + + override func changeStatusEngine() { + if statusEngine == .stop{ + self.statusEngine = .start + }else { + self.statusEngine = .stop + } + } + + func changeHook() { + if statusHook == .unhook{ + self.statusHook = .hook + }else { + self.statusHook = .unhook + } + } +} + + +var newCarAM = SportCar(brand: .AstonMartin, model: "DBS", maxSpeed: 341, color: .purple, modif: .sprint) + +newCarAM.changeMod() +newCarAM.maxSpeed = 300 +newCarAM.changeStatusEngine() +print("Врум Врум, гонка поехала: \(newCarAM.brand.rawValue) \(newCarAM.maxSpeed) км/ч \(newCarAM.modif) \(newCarAM.statusEngine)") + +var newTruck = TruckCar(brand: .KAMAZ, model: "4308", maxTraction: 8000, color: .red) + +newTruck.changeStatusEngine() +newTruck.changeHook() +print(newTruck.brand, newTruck.maxTraction, newTruck.statusHook, newTruck.color, newTruck.statusEngine) diff --git a/lesson_3/3lesson_BesedinVladimir.playground/contents.xcplayground b/lesson_4/4lesson_BesedinVladimir.playground/contents.xcplayground similarity index 100% rename from lesson_3/3lesson_BesedinVladimir.playground/contents.xcplayground rename to lesson_4/4lesson_BesedinVladimir.playground/contents.xcplayground From 9c532f02c04efeb6896b610c11316b504db9d89e Mon Sep 17 00:00:00 2001 From: Vladimir Bes Date: Mon, 2 Mar 2020 19:38:59 +1000 Subject: [PATCH 5/6] no home work --- .../Contents.swift | 134 ------------------ .../Contents.swift | 3 + .../contents.xcplayground | 2 +- 3 files changed, 4 insertions(+), 135 deletions(-) delete mode 100644 lesson_4/4lesson_BesedinVladimir.playground/Contents.swift create mode 100644 lesson_5/5lesson_BesedinVladimir.playground/Contents.swift rename {lesson_4/4lesson_BesedinVladimir.playground => lesson_5/5lesson_BesedinVladimir.playground}/contents.xcplayground (59%) diff --git a/lesson_4/4lesson_BesedinVladimir.playground/Contents.swift b/lesson_4/4lesson_BesedinVladimir.playground/Contents.swift deleted file mode 100644 index 0fd1a38..0000000 --- a/lesson_4/4lesson_BesedinVladimir.playground/Contents.swift +++ /dev/null @@ -1,134 +0,0 @@ -import UIKit - -enum BrandsSportСar: String{ - case McLaren = "McLaren" - case AstonMartin = "Aston Martin" - case Lamborghini = "Lamborghini" - case Ferrari = "Ferrari" -} -enum BrandsCarTruck: String { - case KAMAZ = "КАМАЗ" - case MAN = "MAN" - case HYUNDAI = "Hyundai" - case MERCEDES = "Mercedes" -} - -enum ColorsCars: String { - case yellow = "Желтый" - case red = "Красный" - case black = "Черный" - case purple = "Фиолетовый" -} -enum StateEngine { - case start - case stop -} - -class Car { - let color:ColorsCars - let model:String - var statusEngine:StateEngine - init(model: String ,color: ColorsCars, statusEngine:StateEngine) { - self.model = model - self.color = color - self.statusEngine = statusEngine - } - - func changeStatusEngine () { - - } -} - -class SportCar: Car { - - enum ModsSportCar { - case drift - case sprint - } - - let brand:BrandsSportСar - var maxSpeed: Int - var modif: ModsSportCar - - init(brand: BrandsSportСar, - model: String, - maxSpeed: Int, - color: ColorsCars, - statusEngine: StateEngine = .stop, - modif: ModsSportCar) { - self.brand = brand - self.maxSpeed = maxSpeed - self.modif = modif - super.init(model: model, color: color, statusEngine: statusEngine) - } - - override func changeStatusEngine() { - if statusEngine == .stop{ - self.statusEngine = .start - }else { - self.statusEngine = .stop - } - } - - func changeMod() { - if modif == .sprint{ - self.modif = .drift - }else { - self.modif = .sprint - } - } -} - -class TruckCar: Car { - enum HookTruckCar { - case hook - case unhook - } - - let brand: BrandsCarTruck - let maxTraction: Int - var statusHook: HookTruckCar - - init(brand: BrandsCarTruck, - model: String, - maxTraction: Int, - color: ColorsCars, - statusEngine: StateEngine = .stop, - statusHook: HookTruckCar = .unhook) { - self.brand = brand - self.maxTraction = maxTraction - self.statusHook = statusHook - - super.init(model: model, color: color, statusEngine: statusEngine) - } - - override func changeStatusEngine() { - if statusEngine == .stop{ - self.statusEngine = .start - }else { - self.statusEngine = .stop - } - } - - func changeHook() { - if statusHook == .unhook{ - self.statusHook = .hook - }else { - self.statusHook = .unhook - } - } -} - - -var newCarAM = SportCar(brand: .AstonMartin, model: "DBS", maxSpeed: 341, color: .purple, modif: .sprint) - -newCarAM.changeMod() -newCarAM.maxSpeed = 300 -newCarAM.changeStatusEngine() -print("Врум Врум, гонка поехала: \(newCarAM.brand.rawValue) \(newCarAM.maxSpeed) км/ч \(newCarAM.modif) \(newCarAM.statusEngine)") - -var newTruck = TruckCar(brand: .KAMAZ, model: "4308", maxTraction: 8000, color: .red) - -newTruck.changeStatusEngine() -newTruck.changeHook() -print(newTruck.brand, newTruck.maxTraction, newTruck.statusHook, newTruck.color, newTruck.statusEngine) diff --git a/lesson_5/5lesson_BesedinVladimir.playground/Contents.swift b/lesson_5/5lesson_BesedinVladimir.playground/Contents.swift new file mode 100644 index 0000000..49c1ff6 --- /dev/null +++ b/lesson_5/5lesson_BesedinVladimir.playground/Contents.swift @@ -0,0 +1,3 @@ +import UIKit + +var str = "Hello, playground" diff --git a/lesson_4/4lesson_BesedinVladimir.playground/contents.xcplayground b/lesson_5/5lesson_BesedinVladimir.playground/contents.xcplayground similarity index 59% rename from lesson_4/4lesson_BesedinVladimir.playground/contents.xcplayground rename to lesson_5/5lesson_BesedinVladimir.playground/contents.xcplayground index 5da2641..9f5f2f4 100644 --- a/lesson_4/4lesson_BesedinVladimir.playground/contents.xcplayground +++ b/lesson_5/5lesson_BesedinVladimir.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file From 94212683ab5994c40d47f234e954c1bc434c3c4f Mon Sep 17 00:00:00 2001 From: Vladimir Bes Date: Tue, 10 Mar 2020 21:45:26 +1000 Subject: [PATCH 6/6] lesson-5 --- .../Contents.swift | 127 +++++++++++++++++- .../contents.xcplayground | 2 +- 2 files changed, 127 insertions(+), 2 deletions(-) diff --git a/lesson_5/5lesson_BesedinVladimir.playground/Contents.swift b/lesson_5/5lesson_BesedinVladimir.playground/Contents.swift index 49c1ff6..848d41b 100644 --- a/lesson_5/5lesson_BesedinVladimir.playground/Contents.swift +++ b/lesson_5/5lesson_BesedinVladimir.playground/Contents.swift @@ -1,3 +1,128 @@ import UIKit -var str = "Hello, playground" +enum BrandsSportСar: String{ + case McLaren = "McLaren" + case AstonMartin = "Aston Martin" + case Lamborghini = "Lamborghini" + case Ferrari = "Ferrari" +} +enum BrandsCarTruck: String { + case KAMAZ = "КАМАЗ" + case MAN = "MAN" + case HYUNDAI = "Hyundai" + case MERCEDES = "Mercedes" +} +enum ColorsCars: String { + case yellow = "Желтый" + case red = "Красный" + case black = "Черный" + case purple = "Фиолетовый" +} +enum StateEngine { + case start + case stop +} +enum StateWindows: String { + case openWindow + case closeWindow +} +enum StateDors: String { + case openDor + case closeDor +} + +protocol Car { + var model: String {get} + var year: Int {get} + var colors: ColorsCars {get} + func ChangeStatusEngine (_ state: StateEngine) +} + +extension Car { + func changeStatusWindows (_ state: StateWindows) { + print("Windows \(state)") + } + func changeStatusDor (_ state: StateDors) { + print("Dors \(state)") + } +} + +class SportCar: Car, CustomStringConvertible { + enum ModsSportCar { + case drift + case sprint + } + var brand:BrandsSportСar + var model: String + var year: Int + var colors: ColorsCars + var mod: ModsSportCar + var maxSpeed: Int + var description: String { + "Cоздана новая машина под брендом: \(brand), " + + "Конфигурация: \(mod)" + } + + init(model: String, year: Int, colors: ColorsCars, brand: BrandsSportСar, maxSpeed: Int, mod: ModsSportCar) { + self.model = model + self.year = year + self.colors = colors + self.brand = brand + self.maxSpeed = maxSpeed + self.mod = mod + } + + func ChangeStatusEngine(_ state: StateEngine) { + print("Engine \(state)") + } +} + +class TruckCar: Car { + + enum HookTruckCar { + case hook + case unhook + } + var brand: BrandsCarTruck + var model: String + var year: Int + var colors: ColorsCars + var maxTraction: Int + var statusHook: HookTruckCar + + init(brand: BrandsCarTruck, model: String, year: Int, colors: ColorsCars, maxTraction: Int, statusHook: HookTruckCar) { + self.brand = brand + self.model = model + self.year = year + self.colors = colors + self.maxTraction = maxTraction + self.statusHook = statusHook + } + + func ChangeStatusEngine(_ state: StateEngine) { + print("Endine \(state)") + } + + +} + +extension TruckCar: CustomStringConvertible { + var description: String { + "Создан новый камаз под брендом: \(brand), " + + "Прицеп: \(statusHook)" + } +} + + +var astonM = SportCar(model: "ddd", year: 2000, colors: .purple, brand: .AstonMartin, maxSpeed: 300, mod: .drift) +var kamaz = TruckCar(brand: .KAMAZ, model: "fff", year: 2006, colors: .yellow, maxTraction: 300, statusHook: .unhook) + +astonM.ChangeStatusEngine(.start) +astonM.changeStatusDor(.closeDor) +astonM.changeStatusWindows(.openWindow) +print(astonM) + +kamaz.ChangeStatusEngine(.start) +kamaz.changeStatusWindows(.openWindow) +kamaz.ChangeStatusEngine(.stop) +print(kamaz) diff --git a/lesson_5/5lesson_BesedinVladimir.playground/contents.xcplayground b/lesson_5/5lesson_BesedinVladimir.playground/contents.xcplayground index 9f5f2f4..5da2641 100644 --- a/lesson_5/5lesson_BesedinVladimir.playground/contents.xcplayground +++ b/lesson_5/5lesson_BesedinVladimir.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file