Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
sesiuni:scala:lab8 [2016/07/06 16:57]
ataleanu [Practice]
sesiuni:scala:lab8 [2016/07/06 18:55] (current)
dciocirlan [Practice]
Line 20: Line 20:
   - Define the class ''​RichInteger''​ that takes an Int parameter: <code scala>   - Define the class ''​RichInteger''​ that takes an Int parameter: <code scala>
 class RichInteger(val x: Int)</​code>​ class RichInteger(val x: Int)</​code>​
-    * Define the sqrt method on it. It should do the square root of x. Use an implicit conversion from ''​Int''​ to ''​String''​ to enable this operation on integers.+    * Define the sqrt method on it. It should do the square root of x. Use an implicit conversion from ''​Int''​ to ''​RichInteger''​ to enable this operation on integers.
     * Convert the previous code to an implicit class. How does this help you?     * Convert the previous code to an implicit class. How does this help you?
     * Add an isPrime method to ''​RichInteger''​. It should check whether x is prime or not.     * Add an isPrime method to ''​RichInteger''​. It should check whether x is prime or not.
     * Add the ''​gcd''​ method to ''​RichInteger''​. It should receive another y parameter of type ''​Int''​ and compute the greatest common divisor of the two.     * Add the ''​gcd''​ method to ''​RichInteger''​. It should receive another y parameter of type ''​Int''​ and compute the greatest common divisor of the two.
     * Test the new magic methods you just created.     * Test the new magic methods you just created.
-  - Define a data type for {{http://​semver.org/|semantic versioning}}.+  - Define a data type for {{http://​semver.org |semantic versioning}}.
     * Use a case class and name it ''​Version''​. It should have 3 fields, all integers: ''​major'',​ ''​minor''​ and ''​patch''​.     * Use a case class and name it ''​Version''​. It should have 3 fields, all integers: ''​major'',​ ''​minor''​ and ''​patch''​.
     * Define the ''<''​ operator on the new data type.     * Define the ''<''​ operator on the new data type.
sesiuni/scala/lab8.1467813456.txt.gz · Last modified: 2016/07/06 16:57 by ataleanu