Kotlin multiplatform teoreticky
Příspěvky odeslané z IP adresy 109.74.147.–
nosko.
Jméno
Prelozit to do javy by uz snad nemusel byt nejaky extra problem
import java.util.*
fun main(args: Array<String>) {
val students = mutableListOf<Student>()
fun createStudent() {
val name = readLine("Enter student's name: ")!!
val age = readLine("Enter student's age: ")!!.toInt()
val address = readLine("Enter student's address: ")!!
students.add(Student(name, age, address))
}
fun searchStudent() {
val name = readLine("Enter student's name: ")!!
val student = students.find { it.name == name }
if (student != null) {
println("Student found:")
println(student)
} else {
println("Student not found.")
}
}
fun listStudents() {
println("Listing all students:")
for (student in students) {
println(student)
}
}
println("Welcome to the student records program.")
while (true) {
val option = readLine("What would you like to do? (create, search, list, quit): ")!!
when (option) {
"create" -> createStudent()
"search" -> searchStudent()
"list" -> listStudents()
"quit" -> break
else -> println("Invalid option.")
}
}
}
data class Student(val name: String, val age: Int, val address: String)