class RentDetails { var name: String = "" var days: Int = 0 var price: Double = 0.00 var addItem1: Double = 0.00 var addItem2: Double = 0.00 var addItem3: Double = 0.00 var totalCost: Double = 0.00 func calculateCost() { self.totalCost = Double(self.days) * self.price + self.addItem1 + self.addItem2 + self.addItem3 } } var rentList: [RentDetails] = [] var exit = 0 func displayList() { print("LISTA WYPOŻYCZEŃ\n") var id: Int = 1 for rent in rentList { var addItem1: String? = nil var addItem2: String? = nil var addItem3: String? = nil if rent.addItem1 != 0.00 { addItem1 = " + kask" } if rent.addItem2 != 0.00 { addItem2 = " + gogle" } if rent.addItem3 != 0.00 { addItem3 = " + kijki" } print("\(id). \(rent.name), \(rent.days) dni\(addItem1 ?? "")\(addItem2 ?? "")\(addItem3 ?? ""), CENA: \(rent.price)/dzień, KOSZT: \(rent.totalCost)") id+=1 } } repeat { print("\u{001B}[2J") print("\u{001B}[0;0H") print ("WITAMY W WYPOŻYCZALNI SPRZĘTU NARCIARSKIEGO!\n1. Wypożycz sprzęt\n2. Zobacz listę wypożyczeń\n3. Zwróć sprzęt") let option = readLine() switch option { case "1": print("\u{001B}[2J") print("\u{001B}[0;0H") let rent = RentDetails() print("Imię i nazwisko:") rent.name = readLine() ?? "" print("\nIlość dni:") if let input = readLine() { if let converted = Int(input) { rent.days = converted } } print("\nCena:") if let input = readLine() { if let converted = Double(input) { rent.price = converted } } print("\nDodatkowy kask T/N:") let addItem1 = readLine() if addItem1 == "T" { rent.addItem1 = 15.00 } print("\nDodatkowe gogle T/N:") let addItem2 = readLine() if addItem2 == "T" { rent.addItem2 = 10.00 } print("\nDodatkowe kijki T/N:") let addItem3 = readLine() if addItem3 == "T" { rent.addItem3 = 5.50 } rent.calculateCost() rentList.append(rent) break case "2": print("\u{001B}[2J") print("\u{001B}[0;0H") displayList() print("\n\nKliknij dowolny przycisk, aby powrócić do menu") readLine() break case "3": print("\u{001B}[2J") print("\u{001B}[0;0H") displayList() print("\n\nKliknij ENTER, aby powrócić do menu") print("\nWprowadź ID, aby usunąć") var idToRemove: Int = -1 if let input = readLine() { if let converted = Int(input) { idToRemove = converted - 1 } } if idToRemove == -1 { break } else { rentList.remove(at: idToRemove) } break default: exit = 1 } } while exit == 0