Anonymní profil Jméno – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Anonymní profil Jméno – Programujte.comAnonymní profil Jméno – Programujte.com

 

Příspěvky odeslané z IP adresy 109.74.147.–

nosko.
Software › co zvolit - aplikace pro mob…
2. 10. 2023   #391655

Kotlin multiplatform teoreticky

Jméno
Java › Java + OOP - konzolová apli…
3. 8. 2023   #391496

 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)

 

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý