generated from justuser-31/code_projects_template
65 lines
1.7 KiB
Kotlin
65 lines
1.7 KiB
Kotlin
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} ")
|
|
}
|
|
}
|