当前位置:网站首页>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()
}
}
边栏推荐
- Design and practice of vivo server monitoring architecture
- R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the AIC function to compare the AIC values of the two models (simpl
- QT cannot be edited with UTF-8
- Adding, deleting, querying and modifying MySQL tables
- 抖音實戰~項目關聯UniCloud
- Go language pointer, value reference and pointer reference
- R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用exp函数和coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比(odds ratio)
- Hydropower project construction scheme based on 3D GIS Development
- 7-9 treasure hunt route
- 无鸟用的SAP PA证书,刚入行的同行可以考一考
猜你喜欢

QT cannot be edited with UTF-8
![[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy](/img/d0/7d78b00e4f6ad1e8efb73a5d472b09.png)
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy

Yyds dry goods inventory tells us 16 common usage scenarios of redis at one go

点的螺旋距离

Still using simpledateformat for time formatting? Be careful of project collapse

单调栈以及单调栈的应用

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

Hyperledger Fabric 2. X dynamic update smart contract

How to use stm32subeide SWV function
Record a Webflux application memory leak troubleshooting
随机推荐
Harmonyos accessing database instances (3) -- use ORM bee to test how good harmonyos is
我的为人处事真的有问题吗?
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验
golang convert map to json string
普通人的生活准则
Sword finger offer merges two sorted lists
Common regular expressions
Unveiling the secrets of the Winter Olympics | smartbi's partners supported the "front and back" of the Beijing Winter Olympics
企业数据防泄露解决方案分享
[JS] - [array, stack, queue, linked list basics] - Notes
Window system installation Nacos
22map introduction and API
R language uses GLM function to build Poisson log linear regression model, processes three-dimensional contingency table data to build saturation model, uses summary function to obtain model summary s
抖音实战~实现App端视频上传与发布
7-2 solving the stock buying problem
Yyds dry goods counting uses xshell to implement agent function
Collation of Digital IC design experience (II)
Using ADC to control brushless motor source program STM32 library function
7-8 ladder cloud vertical
R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值(Summarise Data by Categorical Variable)