0% found this document useful (0 votes)
5 views

Kotlin Asignment Set 3 BCA

Uploaded by

somendrasinghch
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Kotlin Asignment Set 3 BCA

Uploaded by

somendrasinghch
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Kotlin Assignment Set 3 -B.Tech..

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.

Use a constructor to initialize the data members.

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)

4. Write a program in Kotlin to design a class Circle2D that contains:


Two double data fields named x and y that specify the center of the circle.
and a data field radius
A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius.
A constructor that creates a circle with the specified x, y, and radius.
A method getArea() that returns the area of the circle.
A method getPerimeter() that returns the perimeter of the circle.
A method contains(double x, double y) that returns true if the specifiedPoint (x, y) is inside
this circle
A method contains(Circle2D circle) that returns true if the specified circle is inside this
circle . Use a method display() to show a circle with its radius and centre as(x,y),area
and perimeter.
Finally develop another class Sphere inherited from the circle with same radius and an
additional method getVolume() calculate the volume
and override getArea() to abtain the surface area of the sphere and the display() method to
represent the sphere with its centre,radius surface area and volume

You might also like