Guest User

Untitled

a guest
Feb 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. class NameShape {
  2. var numberOfSides: Int = 0
  3. var name: String
  4.  
  5. init(name: String) {
  6. self.name = name
  7. }
  8.  
  9. func simpleDescription() -> String{
  10. return "A shape with \(numberOfSides) sides."
  11. }
  12. }
  13.  
  14. var shape: NameShape = NameShape(name: "Triangulo")
  15. shape.numberOfSides = 3
  16. var descripcion = shape.simpleDescription()
  17. print(descripcion)
  18.  
  19. class Square: NameShape {
  20. var sideLength: Double
  21.  
  22. init(sideLength: Double, name: String) {
  23. self.sideLength = sideLength
  24. super.init(name: name)
  25. numberOfSides = 4
  26. }
  27.  
  28. func area() -> Double {
  29. return sideLength * sideLength
  30. }
  31.  
  32. override func simpleDescription() -> String {
  33. return "A square with sides of length \(sideLength)."
  34. }
  35. }
  36.  
  37. let test: Square = Square(sideLength: 5.2, name: "my test square")
  38. test.area()
  39. test.simpleDescription()
  40.  
  41. class Circle: NameShape {
  42. var radius: Double
  43.  
  44. init(radius: Double, name: String) {
  45. self.radius = radius
  46. super.init(name: name)
  47. }
  48.  
  49. func circunference() -> Double {
  50. return radius * 3.1416
  51. }
  52.  
  53. func area() -> Double {
  54. return 3.14159 * radius * radius
  55. }
  56.  
  57. override func simpleDescription() -> String {
  58. return "A circle with a radius of \(radius)."
  59. }
  60. }
  61.  
  62. let círculo: Circle = Circle(radius: 2.5, name: "Menta & Bolita")
  63. print("El área de \(círculo.name) es \(círculo.area()) cm2.")
  64. círculo.name
  65. print(círculo.simpleDescription())
Add Comment
Please, Sign In to add comment