Exercise: Money Operations

Enhance your Kotlin proficiency by implementing crucial operator methods in the Money class.

We'll cover the following

Problem statement

In this exercise, you will work with the Money class, which encapsulates financial details and includes utility methods for Euro currency instances. Your goal is to implement the necessary operator methods to enable the following operations:

Instructions

In the starting code, you have the initial structure of the Money class, which encapsulates financial details and a utility method for Euro currency instances. Your task is to implement the necessary operator methods in the Money class to enable the following operations:

  • Addition of two Money objects using the + operator (throw IllegalArgumentException for different currencies).

  • Subtraction of two Money objects using the - operator (throw IllegalArgumentException for different currencies).

  • Negation of a Money object using the unary - operator.

  • Multiplication of a Money object by an integer using the * operator.

The actual output when running the provided code should be as follows:

Get hands-on with 1400+ tech skills courses.