当前位置:网站首页>Scala IO case
Scala IO case
2022-06-24 23:38:00 【Jue Niu thunder plough hot blade】
import java.io.{
BufferedWriter, FileWriter}
import scala.collection.mutable.ListBuffer
import scala.io.Source
object StuGrade {
case class Student(var name: String,
var chinese: Int,
var math: Int,
var english: Int) {
def getSum: Int = chinese + math + english
}
def main(args: Array[String]): Unit = {
val source = Source.fromFile("./data/student.txt")
val stuArr: Iterator[Array[String]] = source.getLines().map(_.split(" "))
val stuList = ListBuffer[Student]()
// Traverse the acquired object , Encapsulate it as Student After the object , Add to List in
for (s <- stuArr) {
stuList += Student(s(0), s(1).toInt, s(2).toInt, s(3).toInt)
}
// Sort the list in descending order by total score
val sortList = stuList.sortBy(_.getSum).reverse.toList
val bw = new BufferedWriter(new FileWriter("./data/stu.txt"))
for (s <- sortList) {
bw.write(s"${s.name}\t${s.chinese}\t${s.math}\t${s.english}\t${s.getSum}")
bw.newLine()
}
bw.close()
source.close()
}
}
边栏推荐
- 376. machine tasks
- 376. 机器任务
- 7-3 最大子段和
- [JS] - [array application] - learning notes
- QT cannot be edited with UTF-8
- Installing IBM CPLEX academic edition | CONDA installing CPLEX
- R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用exp函数和coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比(odds ratio)
- 企业级~uni-app网络请求封装
- The dplyr package select function of R language moves the specified data column in the dataframe data to the first column (the first column) in the dataframe data column
- 376. 機器任務
猜你喜欢

QT display RGB data

Simpledateformat concrete classes for formatting and parsing dates

抖音实战~项目关联UniCloud

Chapter VI skills related to e-learning 5 (super parameter verification)

Helix distance of point

Spark's wide dependence and narrow dependence yyds dry goods inventory

Understanding openstack network

Mirror image of sword finger offer binary tree

今天睡眠质量记录79分

Design and practice of vivo server monitoring architecture
随机推荐
[JS] - [string - application] - learning notes
R language dplyr package group_ By function and summarize_ The at function calculates the dataframe to calculate the number of counts and the mean value of different groups (summary data by category v
Binary lookup array subscript
去商场逛街
[JS] - [stack, team - application] - learning notes
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
379. hide and seek
Pseudo original intelligent rewriting API Baidu - good collection
257. detention of offenders
Simpledateformat concrete classes for formatting and parsing dates
Quickly build KVM virtual machine on # yyds dry goods inventory # physical machine
Tiktok practice ~ upload and release app video
Actipro WPF Controls 2022.1.2
都2022年了,你还不了解什么是性能测试?
明天就是PMP考试了(6月25日),这些大家都了解了吗?
(Smooth)ScrollToPosition doesn't work properly with RecyclerView
376. 機器任務
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and performs Welch double sample t-test analysis and double inde
7-7 solving mode problems
7-5 maximal submatrix sum problem