Scala for the Impatient: Chapter 7 exercises solutions

I’ve started going through the book: Scala for the Impatient by Cay Horstmann. I’m posting the solution to chapter 7 exercises below.

Advertisements

One thought on “Scala for the Impatient: Chapter 7 exercises solutions

  1. In the last exercise better use: readPassword. Because when you enter your password, characters is not displayed on the screen. So:

    import java.lang.System

    object Greeting extends App {
    val username = System.getProperty(“user.name”)
    val password = Console.readPassword(“Password for ” + username + “: “)
    if(password.mkString.equals(“secret”)) System.out.println(“Hello ” + username)
    else System.err.println(“Invalid password”)
    }

    Thanks for your solutions!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s