Scala
Course Code BDSL456A
CIE Marks 50
Teaching Hours/Week (L:T:P: S) 0:0:2:0
SEE Marks 50
Credits 01
Exam Hours 02
Examination type (SEE) Practical
Experiments
1 a. Write a Scala program to compute the sum of the two given integer values. If the two values are the
same, then return triples their sum.
b. Write a Scala program to check two given integers, and return true if one of them is 22 or if their sum is 32.
2 a. Write a Scala program to remove the character in a given position of a given string. The given position will be in the range 0...string length -1 inclusive.
b. Write a Scala program to create a new string taking the first 5 characters of a given string and return
the string with the 5 characters added at both the front and back.
3 a. Write a Scala program to print the multiplication table of a given number using a for loop.
b. Write a Scala program to find the largest element in an array using pattern matching
4 a. Write a Scala function to calculate the product of digits in a given number
b. Write a Scala function to check if a given number is a perfect square
5 a. Write a Scala program that creates a subclass Student that extends the Person class. Add a property
called grade and implement methods to get and set it.
b. Write a Scala program that creates a class Triangle with properties side1, side2, and side3. Implement a method isEquilateral to check if the triangle is equilateral.
6 a. Write a Scala program that creates an enum class Color with values for different colors. Use the enum class to represent an object's color.
b. Write a Scala program that creates a class ContactInfo with properties name, email, and address. Create a class Customer that includes a ContactInfo object.
7 a. Write a Scala program to create a set and find the difference and intersection between two sets.
b. Write a Scala program to create a set and find the second largest element in the set.
8 a. Write a Scala program to create a list in different ways.
Note: Use Lisp style, Java style, Range list, Uniform list, Tabulate list
b. Write a Scala program to flatten a given List of Lists, nested list structure.
9 a. Write a Scala program to add each element n times to a given list of integers.
b. Write a Scala program to split a given list into two lists.
10 a. Write a Scala program to swap the elements of a tuple Further print no swapping required if elements are same.
b. Write a Scala program to find non-unique elements in a tuple
Suggested Learning Resources:
● Programming Scala, Third Edition, O'Reilly Media.
● Paul Chiusano, Rúnar Bjarnason, Functional Programming in Scala 1st Edition, Manning Publications
● https://docs.scala-lang.org/tutorials/scala-for-java-programmers.html
● https://www.javatpoint.com/scala-tutorial
0 Comments