Please set a PIN

Report a typo

We have a bank card class:

case class CreditCard(number: String, pin: Option[String])

There is a requirement to implement a method that would remind forgetful customers of their card PIN code. It should show the first 2 digits and the rest as asterisks. For example, PIN 1234 would be shown as 12**.

If there is no code, we output Please, set PIN to your card.

Use the higher order fold method to implement the necessary mechanics.

Sample Input 1:

5173

Sample Output 1:

51**
Write a program in Scala 3
case class CreditCard(number: String, pin: Option[String]) {
def remindPin: String = pin.fold(???) { ??? }
}
___

Create a free account to access the full topic