Created
June 8, 2022 10:58
-
-
Save rockvivek/615a1bc3e9ef0ed9cf0e2cd6d4446a38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle{ | |
let height: Double | |
let width: Double | |
init(height: Double, width: Double) { | |
self.height = height | |
self.width = width | |
} | |
func calculateArea() -> Double{ | |
return width * height | |
} | |
} | |
class Circle{ | |
let radius: Double | |
init(radius: Double) { | |
self.radius = radius | |
} | |
func calculateArea() -> Double{ | |
return 3.14 * 3.14 * radius | |
} | |
} | |
class MeasureArea { | |
func area(obj: Rectangle) -> Double{ | |
return obj.calculateArea() | |
} | |
func area(obj: Circle) -> Double{ | |
return obj.calculateArea() | |
} | |
} | |
let measureAreaObj = MeasureArea() | |
let rectObj = Rectangle(height: 5.0, width: 7.0) | |
let circleObj = Circle(radius: 10) | |
print("Area of rect is: \(measureAreaObj.area(obj: rectObj))") | |
print("Area of circle is: \(measureAreaObj.area(obj: circleObj))") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment