-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Se agrega nueva seccion: Prog. Orientada Obj
- Loading branch information
roberto.almaraz
committed
Oct 20, 2017
1 parent
bffaa41
commit f258042
Showing
11 changed files
with
369 additions
and
59 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package Seccion8 | ||
|
||
class Person(){ | ||
var nombre : String? = null | ||
var edad: Int? = null | ||
var altura: Double? = null | ||
var peso: Double? = null | ||
var colorOjos: String? = null | ||
var genero: String? = null | ||
|
||
constructor(nombre: String, edad: Int, altura: Double, peso: Double, colorOjos: String, genero: String): this() { | ||
|
||
this.nombre = nombre | ||
this.edad = edad | ||
this.altura = altura | ||
this.peso = peso | ||
this.colorOjos = colorOjos | ||
this.genero = genero | ||
} | ||
|
||
fun GetNombre(): String? { | ||
return this.nombre | ||
} | ||
|
||
fun GetGenero(): String? { | ||
return this.genero | ||
} | ||
} | ||
|
||
fun main(args: Array<String>){ | ||
var person = Person("Jose", 12,1.50,78.6, "Cafes","Masculino") | ||
println("El nombre es: " + person.GetNombre()) | ||
println("El genero es: " + person.GetGenero()) | ||
|
||
var person2 = Person("Luis", 16,1.60,79.6, "Cafes","Masculino") | ||
println("El nombre es: " + person2.GetNombre()) | ||
println("El genero es: " + person2.GetGenero()) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package Seccion8 | ||
|
||
//La posicion inicia desde 0 como en un Array | ||
enum class Meses { | ||
ENE, FEB, MAR, ABR, MAY, JUN, JUL, AGO, SEP, OCT, NOV, DIC | ||
} | ||
|
||
fun main(args: Array<String>){ | ||
var sextoMes = Meses.JUN | ||
var primerMes = Meses.ENE | ||
|
||
//Nombre del valor en el enum | ||
println("Nombre: " + sextoMes.name) | ||
//Posicion de la constante | ||
println("Posicion: " + sextoMes.ordinal) | ||
|
||
//Nombre del valor en el enum | ||
println("Nombre: " + primerMes.name) | ||
//Posicion de la constante | ||
println("Posicion: " + primerMes.ordinal) | ||
|
||
//Compara segun en el orden en el cual estan separadas dichas constantes | ||
println("Comprar: " + sextoMes.compareTo(primerMes)) | ||
println("Comprar: " + primerMes.compareTo(sextoMes)) | ||
|
||
//Enlista todos los valores del enumerador | ||
for(item in Meses.values()){ | ||
println(item) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package Seccion8 | ||
|
||
//Uso de extensiones para la clase ArrayList | ||
fun ArrayList<String>.intercambiar(indice1: Int, indice2: Int){ | ||
var temporal = this.get(indice1) | ||
this.set(indice1, this.get(indice2)) | ||
this.set(indice2, temporal) | ||
} | ||
|
||
fun main(args: Array<String>){ | ||
|
||
var arrayList = ArrayList<String>() | ||
arrayList.add("Jose") | ||
arrayList.add("Alo") | ||
arrayList.add("Hola") | ||
|
||
println(arrayList) | ||
|
||
arrayList.intercambiar(0,1) | ||
println(arrayList) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package Seccion8 | ||
|
||
//Con esto se puede acceder a la extension a otras clases | ||
open class Humano(){ | ||
//Todas las variables en Kotlin son publicas | ||
var palabra : String? = null | ||
//No se puede hacer una instancia de la variable | ||
//protected var palabra : String? = null | ||
//Solo quien este dentro de la clase principal puede ver esta variable | ||
//private var palabra : String? = null | ||
|
||
open fun saludo(){ | ||
println("Hola") | ||
} | ||
} | ||
|
||
//Solo se puede heredar de una clase una sola vez | ||
class Perro() : Humano(){ | ||
fun ladrido(){ | ||
println("Ladrando") | ||
} | ||
|
||
fun getPalabra(){ | ||
//Manda a llamar a la superclase | ||
super.palabra | ||
} | ||
} | ||
|
||
class Gato() { | ||
fun maullido(){ | ||
println("Miau") | ||
} | ||
} | ||
|
||
fun main(args: Array<String>) { | ||
var persona = Humano() | ||
var juanito = persona.saludo() | ||
|
||
var perrito = Perro() | ||
var coco = perrito.saludo() | ||
|
||
println(persona.palabra) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package Seccion8 | ||
|
||
fun main(args: Array<String>){ | ||
var person = Persona("Jose", 12,1.50,78.6, "Cafes","Masculino") | ||
println("El nombre es: " + person.GetNombre()) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package Seccion8 | ||
|
||
//Clase anidada | ||
class Externa{ | ||
private val nombre: String? = null | ||
|
||
//Poniendo el modificador Inner se pueden acceder a variables | ||
//externas de la clase hijo anidada a la clase padre | ||
inner class Anidada{ | ||
fun mostrar(){ | ||
println("Soy una clase anidada") | ||
println(nombre) | ||
} | ||
} | ||
} | ||
|
||
fun main(args: Array<String>){ | ||
var externa = Externa() | ||
//Antes: var anidada = Externa.Anidada() //Al momemtno de poner el modificador "inner" se agrega parentesis a la clase padre. | ||
var anidada = Externa().Anidada() | ||
anidada.mostrar() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package Seccion8 | ||
|
||
interface Operacion { | ||
//Abstract refiere a que la funcion no tiene cuerpo | ||
//No se pueden crear objetos a partir de una clasa abstracta | ||
fun sum(num1: Int, num2: Int): Int | ||
fun div(num1: Int, num2: Int) | ||
//Funcion implementada dentro de la interfaz | ||
fun multiplicar(num1: Int, num2: Int): Int{ | ||
return num1 * num2 | ||
} | ||
} | ||
|
||
class Oper(): Operacion { | ||
override fun div(num1: Int, num2: Int) { | ||
println("La division es: " + num1/num2) | ||
} | ||
|
||
override fun sum(num1: Int, num2: Int): Int { | ||
return (num1 + num2) * 3 | ||
} | ||
|
||
} | ||
|
||
fun main(args: Array<String>){ | ||
var operacion= Oper() | ||
var miOperacion = operacion.multiplicar(1,2) | ||
|
||
println(miOperacion) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package Seccion8 | ||
|
||
//Clase generica representada con la letra T | ||
class Numeros<T>(numero:T){ | ||
init{ | ||
println(numero) | ||
} | ||
} | ||
|
||
fun <T> imprimir(texto: T){ | ||
println(texto) | ||
} | ||
|
||
fun main(args: Array<String>){ | ||
var numero1 = Numeros<Int>(23) | ||
var numero2 = Numeros<Float>(23.4223f) | ||
var numero3 = Numeros<Double>(23.1321312312) | ||
|
||
imprimir<Int>(12) | ||
imprimir<Double>(12.123) | ||
imprimir<Float>(12.123213123f) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package Seccion8 | ||
|
||
open class Human(){ | ||
var palabra : String? = null | ||
|
||
//Para poder modificarla se pone el modificador open | ||
open fun saludo(){ | ||
println("Hola") | ||
} | ||
} | ||
|
||
class Perr() : Humano(){ | ||
|
||
//Sobrescribe las funciones de saludo de la superclase "Human" | ||
override fun saludo(){ | ||
println("Soy un perro") | ||
} | ||
|
||
fun ladrido(){ | ||
println("Ladrando") | ||
} | ||
} | ||
|
||
fun main(args: Array<String>) { | ||
var persona = Human() | ||
var juanito = persona.saludo() | ||
|
||
var perrito = Perr() | ||
var coco = perrito.saludo() | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package Seccion8 | ||
|
||
class Persona(nombre: String, edad: Int, altura: Double, peso: Double, colorOjos: String, genero: String){ | ||
var nombre : String? = null | ||
var edad: Int? = null | ||
var altura: Double? = null | ||
var peso: Double? = null | ||
var colorOjos: String? = null | ||
var genero: String? = null | ||
|
||
init{ | ||
this.nombre = nombre | ||
this.edad = edad | ||
this.altura = altura | ||
this.peso = peso | ||
this.colorOjos = colorOjos | ||
this.genero = genero | ||
} | ||
|
||
fun GetNombre(): String? { | ||
return this.nombre | ||
} | ||
} | ||
|
||
fun main(args: Array<String>){ | ||
var person = Persona("Jose", 12,1.50,78.6, "Cafes","Masculino") | ||
println("El nombre es: " + person.GetNombre()) | ||
} |