Created
January 26, 2022 03:35
-
-
Save iamkingalvarado/e5d081bca46b098d230c37b458b98f7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| abstract class Animal { | |
| var height: Double = 0.0 | |
| var age: Int = 0 | |
| var weight: Double = 0.0 | |
| var isAlive: Boolean = false | |
| var isLongHair: Boolean? = null | |
| constructor() { | |
| this.isAlive = true | |
| } | |
| constructor(height: Double, weight: Double, age: Int) { | |
| this.height = height | |
| this.weight = weight | |
| this.age = age | |
| } | |
| open fun eat() { | |
| println("El animal está comiendo") | |
| } | |
| fun sleep() { | |
| println("El animal está durmiendo") | |
| } | |
| override fun toString(): String { | |
| return "Weight: $weight, Height: $height, Age: $age" | |
| } | |
| } | |
| enum class Breed { | |
| Pug, | |
| Dalmata, | |
| Terrier, | |
| Unknown | |
| } | |
| open class Dog : Animal { | |
| var breed: Breed | |
| constructor() { | |
| this.breed = Breed.Unknown | |
| } | |
| constructor(breed: Breed) { | |
| this.breed = breed | |
| } | |
| override fun eat() { | |
| println("El perro está comiendo") | |
| } | |
| } | |
| class Cat : Animal() { | |
| override fun eat() { | |
| println("El gato está comiendo") | |
| } | |
| } | |
| abstract class Geometry { | |
| abstract fun area() | |
| abstract fun perimeter() | |
| } | |
| class Circle : Geometry { | |
| var radio: Double | |
| constructor(radio: Double) { | |
| this.radio = radio | |
| } | |
| override fun area() { | |
| println("El area del circulo es = ${(radio * radio) * Math.PI}") | |
| } | |
| override fun perimeter() { | |
| println("El perimetro del circulo es = ${radio * (Math.PI * 2)}") | |
| } | |
| } | |
| class Triangle : Geometry() { | |
| override fun area() { | |
| TODO("Not yet implemented") | |
| } | |
| override fun perimeter() { | |
| TODO("Not yet implemented") | |
| } | |
| } | |
| fun main() { | |
| val dalmata = Dog(Breed.Dalmata) | |
| val pug = Dog(Breed.Pug) | |
| val dog = Dog() | |
| val terrier = Dog(Breed.Terrier) | |
| val circle = Circle(40.0) | |
| val circle2 = Circle(100.0) | |
| val circle3 = Circle(300.0) | |
| circle.area() | |
| val cat = Cat() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment