Profit conversion

Report a typo

You have three coffee machines, and you want to calculate the total profit from these machines. Unfortunately, you have an old function (in the scope) that shows a profit for one machine, and you can't modify it:

def showProfit(amount: Int): String =
  s"Your profit: $amount"

To show the total profit for all three machines, you can use implicit conversions to adapt the existing function for the tuple of machine profits. The following code must compile and show the total profit:

val amount1: Int = 200
val amount2: Int = 450
val amount3: Int = 100

showProfit((amount1, amount2, amount3)) // Your profit: 750 

Sample Input 1:

8 11 5

Sample Output 1:

Your profit: 24
Write a program in Scala 3
given Conversion[???] with ???
___

Create a free account to access the full topic