1. Design a class for Complex numbers in Java. In
addition to methods for basic operations on complex numbers, provide a method
to return the number of active objects created.
ALGORITHM:
step 1:Define the
class complex with the members real,img in double.
step 2:Declare a
static integer variable n and initialise it as 0.
step 3:Using default
constructor,increment the 'n' value by 1 and initialize read & img as0.0.
step 4:Define the
method add() with the returntype complex to add two complex numbers.
step 5:Define the
method sub() with the returntype complex to sub two complex numbers.
step 6:Define the
method read() to get real&img.
step 7:Define the
static method objcount() to count the number if objects created.
step 8:Define the
method print() to display the real & imaginary part.
step 9:Terminate the
class.
step 10:Define the
class compresult and write the main() in it.
step 11:Create
objects for the class complex and access the methods using the objects.
The method objcount
can be accessed using the classname only.
step 12:Display the
result.
step
13:Terminate the main() and the class.
oly 1 program ah?
ReplyDelete