当前位置:网站首页>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()
}
}
边栏推荐
- 单调栈以及单调栈的应用
- 378. Knight placement
- Basic data type
- Adding, deleting, querying and modifying MySQL tables
- Continuous soul torture from two MySQL indexes of interviewers
- Helix distance of point
- Modify stm32f030 clock source to internal crystal oscillator (HEI)
- 7-2 求解买股票问题
- What good smart home brands in China support homekit?
- throttle-debounce.js:一个小型的防抖节流函数库
猜你喜欢

Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
![[JS] - [linked list - application] - learning notes](/img/e1/76d2a347b05212de349322f43e0b3a.png)
[JS] - [linked list - application] - learning notes

Pseudo original intelligent rewriting API Baidu - good collection

Selective sort method

Quickly build KVM virtual machine on # yyds dry goods inventory # physical machine

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

【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化

From client to server

Solution of IP network broadcasting system in Middle School Campus - Design Guide for Campus Digital IP broadcasting system

Morris traversal
随机推荐
Using ADC to control brushless motor source program STM32 library function
Sword finger offer merges two sorted lists
257. detention of offenders
Whereabouts computer desktop small arrow
Start QT program
单调栈以及单调栈的应用
中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南
[basic knowledge] ~ half adder & full adder
Tiktok actual combat ~ sorting out the short video release process
Tremblement de terre réel ~ projet associé unicloud
How to use stm32subeide SWV function
Simple use of libnum Library (hexadecimal string conversion)
22map introduction and API
Mirror image of sword finger offer binary tree
Huawei machine learning service speech recognition function enables applications to paint "sound" and color
376. 机器任务
Helix distance of point
企业数据防泄露解决方案分享
Morris遍曆
Websocket learning