File type checker

Report a typo

Scally started a program that prints the type of the file by the extension of the name. Finish the program below. In case the program doesn't have any information about the extension, set the type to unknown.

Sample Input 1:

a.txt

Sample Output 1:

File a.txt type is plain text
Write a program in Scala 3
object FileTypePrinter extends App {
val extensions = Map(
"txt" -> "plain text",
"scala" -> "Scala source code",
"bin" -> "binary data"
)

val file = scala.io.StdIn.readLine()
val extension = file.reverse.takeWhile(_ != '.').reverse.toLowerCase

println(s"File ??? type is ${extensions.getOrElse(extension, "???")}")
}
___

Create a free account to access the full topic