Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1.  
  2. import Foundation
  3.  
  4. var str = "Hello, playground"
  5. print(str)
  6.  
  7. let moop : Int = 69
  8. let meep : Double = 11.11
  9. let sum = moop + Int(meep)
  10. let sum2 = Double(moop) + meep
  11.  
  12. let sentence = "\(moop) + 1 is 70"
  13.  
  14. var estr = "" //empty string
  15. let isEmpty = estr.isEmpty
  16.  
  17. // Task : Write code to calculate and print the area of a square
  18. let length : Int = 10
  19. // Subtask : Calculate the area of a square
  20. let area1 = length * length
  21. // declare and initialise a variable to hold the length of the side of the square
  22. let sideLength = 10
  23. // declare a variable to hold the calculated area of the square
  24. let area2 = length * sideLength
  25. // assign the calculated value to the variable
  26. let area3 = sideLength * sideLength
  27.  
  28. // Subtask : Print the area of the square
  29. // print the calculated value
  30. let message = "The area of a square of side length \(sideLength) is \(area1)"
  31. print(message)
  32.  
  33. var girlsaregay : Bool = false
  34.  
  35. if (girlsaregay == false) {
  36. let one : Bool = true
  37. let two : Bool = false
  38. let passed = one || two
  39.  
  40. }
  41.  
  42. var temp : Double = 20
  43. if temp > 20 {
  44. print("Too Hot")
  45. } else {
  46. print("Too Cold")
  47. }
  48.  
  49. var temperatureInFahrenheit = 90
  50. if temperatureInFahrenheit <= 32 {
  51. print("It's very cold. Consider wearing a scarf.")
  52. } else if temperatureInFahrenheit >= 86 {
  53. print("It's really warm. Don't forget to wear sunscreen.")
  54. } else {
  55. print("It's not that cold. Wear a t-shirt.")
  56. }
  57.  
  58. //Exercise 1
  59. var kg = 15
  60. let poundconv : Double = 2.2
  61. let result = Double(kg)*poundconv
  62. print("\(kg) kg is \(result) pounds")
  63.  
  64. //Exercise 2
  65. print("The equation for a straight line is given by y = mx + c")
  66. let m : Double = 3.2
  67. let x : Double = 4.4
  68. let c : Double = 10.8
  69. print("The value of y given m(\(m)) x(\(x)) c(\(c)) is 24.88")
  70.  
  71. //Exercise 3
  72. let DIST : Double = 4.0
  73. let A : Double = 4.0
  74. let Bp : Double = 3.5
  75. let B : Double = 3.0
  76. let Cp : Double = 2.5
  77. let C : Double = 2.0
  78. let Dp : Double = 1.5
  79. let D : Double = 1.0
  80. let F : Double = 0.0
  81.  
  82. print("Grade B+ is equal to a grade point of \(Bp)")
  83.  
  84. //Exercise 4
  85. var year : Int = 2100
  86. if year%4 == 0 {
  87. if year%100 == 0 && year%400 != 0 {
  88. print("Year \(year) is not a leap year")
  89. } else if year%100 == 0 && year%400 == 0 {
  90. print("Year \(year) is a leap year")
  91. } else if year%100 != 0 && year%400 != 0 {
  92. print("Year \(year) is a leap year")
  93. }
  94. } else {
  95. print("Year \(year) is not a leap year")
  96. }
  97. //since they appear every 4 years or so
  98.  
  99. //Exercise 5
  100. var feeType = "SPR"
  101.  
  102. if feeType == "SC" {
  103. let TF : Double = 2900.00
  104. let SF : Double = 86.50
  105. let Total = TF+SF
  106. print("Singapore Citizens pay $\(Total) (Tuition Fee: $\(TF), Supplementary Fee: $\(SF)")
  107. } else if feeType == "SPR" {
  108. let TF : Double = 5800.00
  109. let SF : Double = 116.50
  110. let Total = TF+SF
  111. print("Singapore Permanent Residents pay $\(Total) (Tuition Fee: $\(TF), Supplementary Fee: $\(SF)")
  112. } else if feeType == "IS" {
  113. let TF : Double = 10400.00
  114. let SF : Double = 159.50
  115. let Total = TF+SF
  116. print("International Students pay $\(Total) (Tuition Fee: $\(TF), Supplementary Fee: $\(SF)")
  117. }
  118.  
  119. //Exercise 6
  120. var salary : Double = 160000.0
  121. var tax : Double = 0.0
  122. var extra : Double = 0.0
  123. var eftax : Double = 0.0
  124. if salary < 30000 {
  125. extra = salary - 20000
  126. tax = extra * 0.02
  127. eftax = tax / salary
  128.  
  129. } else if salary < 40000 {
  130. extra = salary - 30000
  131. tax = extra * 0.035 + 200
  132. eftax = tax / salary * 100
  133.  
  134. } else if salary < 80000 {
  135. extra = salary - 40000
  136. tax = extra * 0.07 + 550
  137. eftax = tax / salary * 100
  138.  
  139. } else if salary < 120000 {
  140. extra = salary - 80000
  141. tax = extra * 0.115 + 3350
  142. eftax = tax / salary * 100
  143.  
  144. } else if salary < 160000 {
  145. extra = salary - 120000
  146. tax = extra * 0.15 + 7950
  147. eftax = tax / salary * 100
  148.  
  149. } else if salary < 200000 {
  150. extra = salary - 160000
  151. tax = extra * 0.18 + 13950
  152. eftax = tax / salary * 100
  153.  
  154. } else if salary < 240000 {
  155. extra = salary - 200000
  156. tax = extra * 0.19 + 21150
  157. eftax = tax / salary * 100
  158.  
  159. } else if salary < 280000 {
  160. extra = salary - 240000
  161. tax = extra * 0.195 + 28750
  162. eftax = tax / salary * 100
  163.  
  164. } else if salary < 320000 {
  165. extra = salary - 280000
  166. tax = extra * 0.20 + 36550
  167. eftax = tax / salary * 100
  168.  
  169. } else if salary > 320001 {
  170. extra = salary - 32000
  171. tax = extra * 0.22 + 44550
  172. eftax = tax / salary * 100
  173.  
  174. }
  175.  
  176. print("For a salary of $\(salary), the income tax is $\(tax)")
  177. print("The effective income tax rate is \(eftax)%")
  178.  
  179. //Question in class
  180. let width = 10
  181. let height = 25
  182. let area = width*height
  183. print("The area of rectangle with width \(width) and height \(height) is \(area)")
  184.  
  185. var num : Int = 4
  186. if num%2 != 0 {
  187. print("\(num) is an odd number")
  188. } else {
  189. print("\(num) is an even number")
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement