package test_34
//1.迭代器,跳过第一个元素
//2.把字符串转成数字
//3.如何判断一个正整数是否可以被三整除? (1+2+3) % 3 == 0
import scala.collection.mutable.ListBuffer
import scala.io.Source
case class Student(name:String,yuwen:Int,shuxue:Int,total:Int,avg:Int)
//成绩分析
object test {
def main(args: Array[String]): Unit = {
//0.定义一个空列表
val list=ListBuffer[Student]()
//1.读入成绩 按行去读取 跳过第一个元素
val it = Source.fromFile("score.txt").getLines().drop(1)
while (it.hasNext) {
val content=it.next()
//使用中文的逗号去拆分字符串
var arr =content.split(",")
val name =arr(0)
val yuwen =arr(1).toInt
val shuxue =arr(2).toInt
val yingyu=arr(3).toInt
val total =yuwen + shuxue + yingyu
val avg = total / 3
//
list += Student(name,yuwen,shuxue,yingyu,total,avg)
// println("当前行是",name,yingyu,total,avg)
}
val orderList =list.sortWith((a,b)=>a.total>b.total)
orderList.foreach(s=>println(s"姓名${s.name},总分${s.total}"))
}
}