Skip to content

Instantly share code, notes, and snippets.

@djgoldsmith
Created May 14, 2018 03:47
Show Gist options
  • Save djgoldsmith/907424267ae067fe58321b8512a20fed to your computer and use it in GitHub Desktop.
Save djgoldsmith/907424267ae067fe58321b8512a20fed to your computer and use it in GitHub Desktop.
class Shape {
//Shapes will have a number of sides
var numberOfSides = 0
var name: String
//Constructor
init(name: String){
self.name = name
}
//Place Holder for Area Functions
func calcArea() -> Double {}
//Place Holder for Perimeter function
func calcPerimeter() -> Double {}
//A simple Function to return the numberr of sides
func description() -> String {
return ("\(name): a Shape with \(numberOfSides) sides")
}
}
class Rectange: Shape {
//Variables specific to rectangles
var width = 0.0
var height = 0.0
init(width: Double, height: Double){
//First update Superclass using its init method
super.init(name: "Rectangle")
numberOfSides = 4 //And update the number of sides
//Then Class Specific
self.width = width
self.height = height
}
override func calcArea() -> Double {
return height*width
}
override func calcPerimeter() -> Double {
return 2*(height+width)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment