Initial Commit
This commit is contained in:
32
.gitignore
vendored
Normal file
32
.gitignore
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
### IntelliJ IDEA ###
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### Kotlin ###
|
||||||
|
.kotlin
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
||||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
10
.idea/codeStyles/Project.xml
generated
Normal file
10
.idea/codeStyles/Project.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<JetCodeStyleSettings>
|
||||||
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
|
</JetCodeStyleSettings>
|
||||||
|
<codeStyleSettings language="kotlin">
|
||||||
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
||||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="ReplaceUntilWithRangeUntil" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
10
.idea/kotlinc.xml
generated
Normal file
10
.idea/kotlinc.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Kotlin2JvmCompilerArguments">
|
||||||
|
<option name="jvmTarget" value="1.8" />
|
||||||
|
</component>
|
||||||
|
<component name="KotlinCommonCompilerArguments">
|
||||||
|
<option name="apiVersion" value="2.1" />
|
||||||
|
<option name="languageVersion" value="2.1" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
17
.idea/libraries/KotlinJavaRuntime.xml
generated
Normal file
17
.idea/libraries/KotlinJavaRuntime.xml
generated
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="KotlinJavaRuntime" type="repository">
|
||||||
|
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib:2.1.0" />
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.1.0/kotlin-stdlib-2.1.0.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.1.0/kotlin-stdlib-2.1.0-javadoc.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
|
||||||
|
</JAVADOC>
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.1.0/kotlin-stdlib-2.1.0-sources.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="homebrew-23" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/ProyectoKotlin.iml" filepath="$PROJECT_DIR$/ProyectoKotlin.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
15
ProyectoKotlin.iml
Normal file
15
ProyectoKotlin.iml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
34
src/Main.kt
Normal file
34
src/Main.kt
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
fun main() {
|
||||||
|
// Imprimir mensaje en la pantalla
|
||||||
|
println("Welcome to Entornos de Desarrollo")
|
||||||
|
|
||||||
|
// Ejemplo de sentencia alternativa (if-else)
|
||||||
|
val edad = 20
|
||||||
|
if (edad >= 18) {
|
||||||
|
println("Eres mayor de edad.")
|
||||||
|
} else {
|
||||||
|
println("Eres menor de edad.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uso de la estructura when (equivalente a switch)
|
||||||
|
val dia = "Sábado"
|
||||||
|
when (dia) {
|
||||||
|
"Lunes", "Martes", "Miércoles", "Jueves", "Viernes" -> println("Es un día laboral.")
|
||||||
|
"Sábado", "Domingo" -> println("Es fin de semana.")
|
||||||
|
else -> println("Día no válido.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle for para contar hasta 5
|
||||||
|
println("Contando hasta 5:")
|
||||||
|
for (i in 1..5) {
|
||||||
|
println("Número: $i")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle while para una cuenta regresiva
|
||||||
|
var contador = 3
|
||||||
|
println("Cuenta regresiva:")
|
||||||
|
while (contador > 0) {
|
||||||
|
println("Quedan $contador segundos")
|
||||||
|
contador--
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/empresa/Colecciones.kt
Normal file
27
src/empresa/Colecciones.kt
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package empresa
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demostración básica de colecciones en Kotlin:
|
||||||
|
* - List, mutableList
|
||||||
|
* - Operaciones funcionales como map, filter, etc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val readOnlyList = listOf("Manzana", "Pera", "Fresa")
|
||||||
|
val mutableFruits = mutableListOf("Banana", "Mango", "Melón")
|
||||||
|
|
||||||
|
println("Lista inmutable: $readOnlyList")
|
||||||
|
println("Lista mutable antes: $mutableFruits")
|
||||||
|
|
||||||
|
// Agregar y remover elementos en una lista mutable
|
||||||
|
mutableFruits.add("Kiwi")
|
||||||
|
mutableFruits.remove("Mango")
|
||||||
|
println("Lista mutable después: $mutableFruits")
|
||||||
|
|
||||||
|
// Operaciones de filtrado y transformación
|
||||||
|
val filtered = readOnlyList.filter { it.contains("a") }
|
||||||
|
val upperCased = readOnlyList.map { it.uppercase() }
|
||||||
|
|
||||||
|
println("Elementos con 'a': $filtered")
|
||||||
|
println("Elementos en mayúsculas: $upperCased")
|
||||||
|
}
|
||||||
35
src/empresa/Funciones.kt
Normal file
35
src/empresa/Funciones.kt
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package empresa
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ejemplo de diferentes formas de definir funciones en Kotlin.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Función tradicional
|
||||||
|
fun add(a: Int, b: Int): Int {
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Función con expresión
|
||||||
|
fun multiply(a: Int, b: Int) = a * b
|
||||||
|
|
||||||
|
// Función con parámetro opcional
|
||||||
|
fun greet(name: String = "Invitado") { // Valor de la variable por defecto
|
||||||
|
println("Hola, $name")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Función de extensión para la clase String
|
||||||
|
fun String.firstLetter(): Char {
|
||||||
|
return this[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
println("add(3, 4) = ${add(3, 4)}")
|
||||||
|
println("multiply(3, 4) = ${multiply(3, 4)}")
|
||||||
|
|
||||||
|
greet("Kotlin") // Saludo a Kotlin
|
||||||
|
greet() // Usa el valor por defecto "Invitado"
|
||||||
|
|
||||||
|
val sampleText = "Kotlin"
|
||||||
|
println("Primera letra de $sampleText: ${sampleText.firstLetter()}")
|
||||||
|
}
|
||||||
22
src/empresa/Refactorizar.kt
Normal file
22
src/empresa/Refactorizar.kt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package empresa
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Código preparado para practicar refactorizaciones en IntelliJ IDEA CE
|
||||||
|
* - Renombrar variables y funciones
|
||||||
|
* - Extraer funciones
|
||||||
|
* - Inlinar variables
|
||||||
|
* - Etc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
// Ejemplo de código repetido que podemos refactorizar
|
||||||
|
val number1 = 10 // Renombrar variable
|
||||||
|
val number2 = 20 // Seleccionar number > Inline Property
|
||||||
|
|
||||||
|
// Lógica repetida (ej: cálculo sencillo)
|
||||||
|
val result1 = number1 * number1 + number1 // Extraer función
|
||||||
|
println("Resultado 1: $result1")
|
||||||
|
|
||||||
|
val result2 = number2 * number2 + number2
|
||||||
|
println("Resultado 2: $result2")
|
||||||
|
}
|
||||||
47
src/empresa/SintaxisBasica.kt
Normal file
47
src/empresa/SintaxisBasica.kt
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package empresa
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demostración de sintaxis básica de Kotlin:
|
||||||
|
* - Declaración de variables
|
||||||
|
* - Al poner el cursor sobre una variable, se muestra donde se referencia y su tipo
|
||||||
|
* - Uso de if/else y bucles
|
||||||
|
* - Prueba de Debugger
|
||||||
|
*/
|
||||||
|
fun main() {
|
||||||
|
// Kotlin tiene val (inmutable) y var (mutable)
|
||||||
|
val inmutableNumber = 10
|
||||||
|
var mutableNumber = 5
|
||||||
|
|
||||||
|
println("inmutableNumber = $inmutableNumber")
|
||||||
|
println("mutableNumber = $mutableNumber")
|
||||||
|
|
||||||
|
// Podemos modificar 'var', pero no 'val'
|
||||||
|
mutableNumber = 20
|
||||||
|
println("mutableNumber modificado = $mutableNumber")
|
||||||
|
|
||||||
|
// Condiciones if/else
|
||||||
|
val message = if (mutableNumber > 10) {
|
||||||
|
"El número es mayor que 10"
|
||||||
|
} else {
|
||||||
|
"El número es menor o igual a 10"
|
||||||
|
}
|
||||||
|
println(message)
|
||||||
|
|
||||||
|
// Bucles (for e in y while)
|
||||||
|
println("Bucle for:")
|
||||||
|
for (i in 1..5) { // 1..5 incluye 1,2,3,4,5
|
||||||
|
println("i = $i")
|
||||||
|
}
|
||||||
|
|
||||||
|
println("Bucle for con saltos de 2:")
|
||||||
|
for (i in 1..5 step 2) { // 1,3,5
|
||||||
|
println("i = $i")
|
||||||
|
}
|
||||||
|
|
||||||
|
println("Bucle while:")
|
||||||
|
var counter = 0
|
||||||
|
while (counter < 3) {
|
||||||
|
println("counter = $counter") // Se puede meter una variable dentro un string sin concatenar
|
||||||
|
counter++
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user