Can some help with Scala code for below Lab requirement

Write a function show using Option which returns the value of string . If inputCapital has a value show it must return the value, and if the value is None , return invalid . Print country name and capital as in the sample output format.

when executing with scala Options India .

Output will be: India : New Delhi

Need help to proceed with lab learning

Can you explain where you are getting stuck when you attempt to solve it yourself?

1 Like

object Options extends App {
val input = args(0)
val capitals = Map(“France” -> “Paris”, “Japan” -> “Tokyo”, “India” -> “New Delhi”, “Russia” -> “Moscow”)
val inputCapital = capitals.get(input)
println((“India” ) : + capitals.get( “India” ))

this code says
Options.scala:7: error: identifier expected but ‘.’ found.
println(“India”) : + capitals.get( “India” )

Hmm. I suspect the error message is misleading, and that the problem is actually that colon there. What do you expect ("India") : + capitals.get() to mean?

More generally: it’s a little hard to help you, because you aren’t formatting your code and it’s hard to read. Please, when you post code samples here, put them in code blocks. Before your code, put a line that contains just three backticks – just ``` on a line by itself – and then another one after your code. That’s absolutely essential to making your code readable, and is polite to the people trying to help. Thanks!

1 Like