Kotlin Asignment Set 3 BCA
Kotlin Asignment Set 3 BCA
1. Write a program in Kotlin to develop a class cmplx to represent a complex number that
contains real and imaginary part of a complex no. The class must have a constructor to
input values and a default one as well.
Design member methods to perform the following:
a. Add another complex no and store the result as another complex no. object.
b. Multiply another complex no and store the result as another complex no.
object.
c. Use a display method to display each complex no in x +i*y format
2. Write a program in Kotlin to design a class rational that has two integer data members
numerator and denominator.
Write constructors to initialize the data members with an exception being enabled when the
denominator is zero.
Design member methods to perform the following :
Find LCM of the two denominators for two given rational objects respectively.
Using the above method add another rational object and store in a rational object output.
Use a show method to represent each rational object in x/y format.
3. Write a program in Kotlin to design a class myTime that contains integer members as hour,
minute and seconds.
Design two overloaded methods to add time in minutes (<1440 ) or hours(<24) with a
myTime class object and return a final time( if it exceeds 2400 hrs – represent it as day 2 and
the corresponding time).
Use a method displayTime() to show the time in HH:MM:SS format with [day 2] (if
necessary)