Facebook
From Fiery Giraffe, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 45
  1. class RentDetails {
  2.     var name: String = ""
  3.     var days: Int = 0
  4.     var price: Double = 0.00
  5.     var addItem1: Double = 0.00
  6.     var addItem2: Double = 0.00
  7.     var addItem3: Double = 0.00
  8.     var totalCost: Double = 0.00
  9.  
  10.     func calculateCost() {
  11.         self.totalCost = Double(self.days) * self.price + self.addItem1 + self.addItem2 + self.addItem3
  12.     }
  13. }
  14.  
  15. var rentList: [RentDetails] = []
  16. var exit = 0
  17.  
  18. func displayList() {
  19.   print("LISTA WYPOŻYCZEŃ\n")
  20.   var id: Int = 1
  21.  
  22.   for rent in rentList {
  23.     var addItem1: String? = nil
  24.     var addItem2: String? = nil
  25.     var addItem3: String? = nil
  26.     if rent.addItem1 != 0.00
  27.     {
  28.       addItem1 = " + kask"
  29.     }
  30.     if rent.addItem2 != 0.00
  31.     {
  32.       addItem2 = " + gogle"
  33.     }
  34.     if rent.addItem3 != 0.00
  35.     {
  36.       addItem3 = " + kijki"
  37.     }
  38.     print("\(id). \(rent.name), \(rent.days) dni\(addItem1 ?? "")\(addItem2 ?? "")\(addItem3 ?? ""), CENA: \(rent.price)/dzień, KOSZT: \(rent.totalCost)")
  39.     id+=1
  40.   }
  41. }
  42.  
  43. repeat {
  44.   print("\u{001B}[2J")
  45.   print("\u{001B}[0;0H")
  46.   print ("WITAMY W WYPOŻYCZALNI SPRZĘTU NARCIARSKIEGO!\n1. Wypożycz sprzęt\n2. Zobacz listę wypożyczeń\n3. Zwróć sprzęt")
  47.   let option = readLine()
  48.   switch option {
  49.     case "1":
  50.       print("\u{001B}[2J")
  51.       print("\u{001B}[0;0H")
  52.       let rent = RentDetails()
  53.       print("Imię i nazwisko:")
  54.       rent.name = readLine() ?? ""
  55.       print("\nIlość dni:")
  56.       if let input = readLine()
  57.       {
  58.         if let converted = Int(input)
  59.         {
  60.             rent.days = converted
  61.         }
  62.       }
  63.       print("\nCena:")
  64.       if let input = readLine()
  65.       {
  66.         if let converted = Double(input)
  67.         {
  68.             rent.price = converted
  69.         }
  70.       }
  71.       print("\nDodatkowy kask T/N:")
  72.       let addItem1 = readLine()
  73.       if addItem1 == "T"
  74.       {
  75.         rent.addItem1 = 15.00
  76.       }
  77.       print("\nDodatkowe gogle T/N:")
  78.       let addItem2 = readLine()
  79.       if addItem2 == "T"
  80.       {
  81.         rent.addItem2 = 10.00
  82.       }
  83.       print("\nDodatkowe kijki T/N:")
  84.       let addItem3 = readLine()
  85.       if addItem3 == "T"
  86.       {
  87.         rent.addItem3 = 5.50
  88.       }
  89.  
  90.       rent.calculateCost()
  91.       rentList.append(rent)
  92.     break
  93.  
  94.     case "2":
  95.       print("\u{001B}[2J")
  96.       print("\u{001B}[0;0H")
  97.       displayList()
  98.  
  99.       print("\n\nKliknij dowolny przycisk, aby powrócić do menu")
  100.       readLine()
  101.     break
  102.  
  103.     case "3":
  104.       print("\u{001B}[2J")
  105.       print("\u{001B}[0;0H")
  106.       displayList()
  107.  
  108.       print("\n\nKliknij ENTER, aby powrócić do menu")
  109.       print("\nWprowadź ID, aby usunąć")
  110.       var idToRemove: Int = -1
  111.       if let input = readLine()
  112.       {
  113.         if let converted = Int(input)
  114.         {
  115.             idToRemove = converted - 1
  116.         }
  117.       }
  118.       if idToRemove == -1
  119.       {
  120.         break
  121.      
  122.       }
  123.       else
  124.       {
  125.         rentList.remove(at: idToRemove)
  126.       }
  127.     break
  128.  
  129.     default: exit = 1
  130.   }
  131. } while exit == 0