Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My Submission for Kotlin assignment- Akshat Goel #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
Binary file added src/main/kotlin/.DS_Store
Binary file not shown.
43 changes: 36 additions & 7 deletions src/main/kotlin/assignment/Assignment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package assignment

// INSTRUCTIONS:
import java.io.File
// INSTRUCTIONS:
// 1. Read a list of student responses from text file
// 2. Filter students who are not covid positive
// 3. Sort them according to their branches, within each branch sort by names
Expand All @@ -21,13 +21,42 @@ fun main() {
}

fun readResponses(): List<Response> {
TODO()
}
val fileName= "src/main/kotlin/assignment/responses.txt"
val file =File(fileName)
return file.readLines()
.drop(1)
.map{ val words=it.trim().split(Regex(" +"))
Response(
name= words[1],
rollNumber = words[2].toInt(),
branch = words[3],
covidPositive = words[4].toBoolean()
)
}

}

fun processResponses(responses: List<Response>): List<List<Response>>{
val temp = (responses.filterNot { it.covidPositive }).sortedWith(compareBy({it.branch},{it.name}))

val temp1=((temp.groupBy{it.branch}.values).chunked(3)).map{it.flatten()}
print(temp1)
return temp1

fun processResponses(responses: List<Response>): List<List<Response>> {
TODO()
}

fun writeToFile(batches: List<List<Response>>) {
TODO()
val fileName= "src/main/kotlin/assignment/batchesNew.txt"
val file = File(fileName)
file.createNewFile()
file.writeText("")
for (index in 0 until batches.size){
println(index)
file.appendText("Batch ${index+1}:\n")
for(j in batches[index].indices){
file.appendText("${j+1}.\t\t${batches[index][j].name}\t\t${batches[index][j].rollNumber}\t\t ${batches[index][j].branch}")
file.appendText("\n")
}
file.appendText("\n")
}
}
31 changes: 31 additions & 0 deletions src/main/kotlin/assignment/batchesNew.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Batch 1:
1. Chloe 4283661 CHE
2. Jack 5672351 CHE
3. James 8429918 CHE
4. Peter 3234291 CHE
5. Emily 4736471 CIV
6. Charles 3491897 CSE
7. Jacob 3246617 CSE
8. Lily 3462691 CSE
9. Lucy 3248462 CSE
10. Sophia 1263612 CSE

Batch 2:
1. Harry 1278934 ECE
2. Hazel 2361718 ECE
3. Oliver 2138129 ECE
4. Angel 1317382 EEE
5. Jasper 2366236 EEE
6. Clara 4328992 MAT
7. Eliana 9090341 MAT
8. Sarah 1334921 MAT

Batch 3:
1. Kevin 4271786 MEC
2. Daisy 7364891 MIN
3. Daniel 8783261 MIN
4. William 4662376 MIN
5. Nora 4123894 PHE
6. Owen 4898291 PHE
7. Ryan 9071271 PHE