---
# System prepended metadata

title: Question

---

# Question

Implement the method `retrieveAddress` using the methods `getStreet1`, `getStreet2`, and `getStreet3` to create an `Address`.

```scala::
case class Address(
  street1: String,
  street2: Option[String],
  street3: Option[String]
)

def retrieveAddress(userId: String):Option[Address] = {
    // TODO: Implement
    if (userId.isEmpty) {
        None
    } else {
        Try(getStreet(userId)) match {
            case Success(str) => Some(Address(
              str,
            Try(getStreet2(userId)).toOption,
            Try(getStreet3(userId)).toOption
            ))
            case Failure(th) => None
        }
        
    }
}


/**
  * Retrieves the main street address.
  *
  * @throws RuntimeException if empty
  */
def getStreet1(userId: String): String = {
  // implementation
}

/**
  * Retrieves additional street address line 2.
  *
  * @throws RuntimeException if empty
  */
def getStreet2(userId: String): String = {
  // implementation
}

/**
  * Retrieves additional street address line 3.
  *
  * @throws RuntimeException if empty
  */
def getStreet3(userId: String): String = {
  // implementation
}

```
