From the course: Scala Essential Training for Data Science

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Creating operations in Scala

Creating operations in Scala

- [Instructor] Now, let's create a class and define an operation under this class. We're going to work with a two dimensional point, so let's create a class called point2d, and let's have two parameters, coordinate one, which is an integer, and coordinate two, which is also an integer. And in this class, we're going to have a couple of variables. We will have a, which is an integer, and its value is set to whatever coord1 is, coordinate one, and similarly, we're going to have var b, which is an integer, and it's going to have the value as whatever's passed into coordinate two. So, that'll define where a point is located, but then we also want to have the option of moving that point, so let's create a move operation. In the move operation, we will have two parameters that indicate how much something should be moved, how much that point should be moved, so we'll call that delta_a, which will be an integer, and then we'll have delta_b, which will also be an integer. And those will be the…

Contents