generated from justuser-31/code_projects_template
Выгрузка всех файлов
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "2.1.10"
|
||||
application
|
||||
}
|
||||
|
||||
group = "org.example"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(kotlin("test"))
|
||||
implementation("com.beust:klaxon:5.5")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
// "run" task
|
||||
application {
|
||||
mainClass.set("org.example.MainKt") // Replace with your actual main class
|
||||
}
|
||||
|
||||
tasks.register<JavaExec>("runWithInput") {
|
||||
group = "application"
|
||||
mainClass.set("org.example.MainKt")
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
standardInput = System.`in` // 👈 enables readln() or readLine()
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.example
|
||||
import com.beust.klaxon.*
|
||||
import java.io.File
|
||||
import java.lang.ProcessBuilder.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
data class Grades(
|
||||
val math: Int,
|
||||
val physics: Int,
|
||||
val history: Int
|
||||
)
|
||||
|
||||
data class Student(
|
||||
val name: String,
|
||||
val age: Int,
|
||||
val grades: Grades
|
||||
)
|
||||
|
||||
fun String.runCommand(workingDir: File) {
|
||||
ProcessBuilder(*split(" ").toTypedArray())
|
||||
.directory(workingDir)
|
||||
.redirectOutput(Redirect.INHERIT)
|
||||
.redirectError(Redirect.INHERIT)
|
||||
.start()
|
||||
.waitFor(60, TimeUnit.MINUTES)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val file = File("src/main/resources/data.json")
|
||||
var rawData = file.readText()
|
||||
var json = Klaxon().parseArray<Student>(rawData)
|
||||
|
||||
var averageBest: Float = 0f
|
||||
var averageBestI: Int = 0
|
||||
var stud_80_plus: Array<Student> = arrayOf()
|
||||
var averBal: Float = 0f;
|
||||
if (json != null) {
|
||||
var el: Student;
|
||||
for (i in 0..<json.size) {
|
||||
//println(i.name)
|
||||
el = json.get(i)
|
||||
averBal = ((el.grades.math + el.grades.history + el.grades.physics)/3).toFloat()
|
||||
if (averBal > averageBest) {
|
||||
averageBest = averBal
|
||||
averageBestI = i
|
||||
}
|
||||
if (el.grades.math > 80) {
|
||||
stud_80_plus += el
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val aver = json?.get(averageBestI)
|
||||
println("""
|
||||
Student with best average score:
|
||||
${aver?.name} ${aver?.age} ${aver?.grades?.math} ${aver?.grades?.physics} ${aver?.grades?.history}
|
||||
|
||||
""".trimIndent())
|
||||
|
||||
println("Students with 80+ math scores:")
|
||||
for (i in stud_80_plus) {
|
||||
println("${i.name} ${i.age} ${i.grades.math} ${i.grades.physics} ${i.grades.history} ")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user