-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStore.kt
More file actions
43 lines (32 loc) · 971 Bytes
/
Store.kt
File metadata and controls
43 lines (32 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package storage
import model.Cell
import model.Pizza
import model.Slice
import java.io.File
import java.util.*
class Store {
fun read(fileName: String): Pizza {
val scanner = Scanner(File(fileName))
val R = scanner.nextInt()
val C = scanner.nextInt()
val L = scanner.nextInt()
val H = scanner.nextInt()
scanner.nextLine()
val pizza = Array(R) { index ->
var line = scanner.nextLine()
val row = Array(C) { index ->
Cell(line[index].toString(), false)
}
row
}
return Pizza(pizza, R, C, L, H)
}
fun write(fileName: String, slices: List<Slice>) {
File("$fileName").printWriter().use { out ->
out.println("${slices.size}")
slices.forEach { slice ->
out.println("${slice.startRow} ${slice.startColumn} ${slice.endRow} ${slice.endColumn}")
}
}
}
}