PROGRAMMING PARADIGMS LAB 8 Remark: If the exercise gives the name of a function and the…
- User
PROGRAMMING PARADIGMS LAB 8 Remark: If the exercise gives the name of a function and the arguments it takes, then the function must look like this. You can create a new function inside this one that takes more arguments! Recall the principles of functional programming that you learned in previous classes, including: pure functions and immutability. Wherever you work with lists, use pattern matching instead of plain if-else whenever possible. Whenever possible, use tail recursion. Prepare some examples showing how your code works - remember to include boundary values, e.g. empty lists, all elements that meet/fail conditions, different functions in high-order functions, etc. All of the above will be taken into account when grading assignments. If you want you can practice on these exercises, you will not receive points for the first 4 exercises. Solving them is NOT mandatory! Remember to write each module in different file. Exercise 1 0p Create a module named MathOperations with basic arithmetic methods (e.g., add, subtract, multiply, divide). Write a main program in a separate file or object that imports the MathOperations module. using an alias. Use functions from MathOperations module. Exercise 2 0p Define a module Geometry with methods areaOfCircle, areaOfRectangle, and areaOfTriangle. Import only areaOfCircle, use it to calculate area. Exercise 3 0p Define a singleton object ConfigManager with methods like getConfig and setConfig. Use this singleton to manage configuration values in a separate program. Exercise 4 0p Create a module MathUtils with two overloaded calculate methods:
- One that takes two Int parameters and returns their sum.
- Another that takes two Double parameters and returns their product. Exercise 5 4p Create a module ShapeOperations with methods: • calculate for calculating the area of a rectangle (takes two Int parameters). • calculate for calculating the area of a triangle (takes two Double parameters). Create another module MathOperations with methods: • calculate for adding two numbers (takes two Int parameters). Write the main program that will use all methods. solve this tasks in scala. write small comments explaining the code do it in one file called Main.scala
- Assistant