0% found this document useful (0 votes)
4 views14 pages

Complex

The document contains multiple Java classes for handling complex numbers, including operations such as addition, subtraction, multiplication, and division. Each class (Complex, Complex1, Complex2, Complex3) implements these operations differently, with variations in how they manage state and return results. Additionally, there are driver classes (Driver, Driver1, Driver2, Driver3) that provide a user interface for interacting with the complex number classes through a console menu.

Uploaded by

Safwan Mohamed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views14 pages

Complex

The document contains multiple Java classes for handling complex numbers, including operations such as addition, subtraction, multiplication, and division. Each class (Complex, Complex1, Complex2, Complex3) implements these operations differently, with variations in how they manage state and return results. Additionally, there are driver classes (Driver, Driver1, Driver2, Driver3) that provide a user interface for interacting with the complex number classes through a console menu.

Uploaded by

Safwan Mohamed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Complex

public class Complex {

private float real;

private float img;

Complex()

real=0;

img=0;

Complex(float real, float img)

[Link] =real;

[Link] = img;

public void Add(Complex c1, Complex c2)

float areal,aimg;

areal = ([Link] + [Link]);

aimg = ([Link] + [Link]);

[Link]("Addition is "+areal+" "+aimg+"i");

public void Sub(Complex c1, Complex c2)

float sreal,simg;

sreal = ([Link] - [Link]);

simg =([Link] -[Link]);

[Link]("Subtraction is "+sreal+" "+simg+"i");

public void Mult(Complex c1, Complex c2)


{

float mreal,mimg;

mreal =([Link]*[Link] - [Link]*[Link]);

mimg = ([Link]*[Link]+[Link]*[Link]);

[Link] ("Multiplication is "+mreal+" "+mimg+"i");

public void Divide(Complex c1,Complex c2)

float dreal, dimg, deno;

deno = [Link]*[Link] + [Link]*[Link];

dreal = ([Link]*[Link]+[Link]*[Link]);

dimg = ([Link]*[Link] - [Link]*[Link]);

[Link]("Division is ("+dreal+" "+dimg+"i) /"+deno);

Complex1
public class Complex1 {

private float real;

private float img;

private float eno;

Complex1()

real=0;

img=0;

Complex1(float real, float img)

[Link] =real;

[Link] = img;

}
public void Add(Complex1 c1, Complex1 c2)

Complex1 c3 = new Complex1 ();

[Link] = ([Link] + [Link]);

[Link] = ([Link] + [Link]);

[Link]("Addition is "+[Link]+" "+[Link]+"i");

public void Sub(Complex1 c1, Complex1 c2)

Complex1 c3 = new Complex1 ();

[Link] = ([Link] - [Link]);

[Link] =([Link] -[Link]);

[Link]("Subtraction is "+[Link]+" "+[Link]+"i");

public void Mult(Complex1 c1, Complex1 c2)

Complex1 c3 = new Complex1 ();

[Link] =([Link]*[Link] - [Link]*[Link]);

[Link] = ([Link]*[Link]+[Link]*[Link]);

[Link] ("Multiplication is "+[Link]+" "+[Link]+"i");

public void Divide(Complex1 c1,Complex1 c2)

Complex1 c3 = new Complex1 ();

[Link] = [Link]*[Link] + [Link]*[Link];

[Link] = ([Link]*[Link]+[Link]*[Link]);

[Link] = ([Link]*[Link] - [Link]*[Link]);

[Link]("Division is ("+[Link]+" "+[Link]+"i) /"+[Link]);

}
Complex2
public class Complex2 {

public float real;

public float img;

public float eno;

Complex2()

real=0;

img=0;

Complex2(float real, float img)

[Link] =real;

[Link] = img;

public Complex2 Add(Complex2 c1, Complex2 c2)

Complex2 c3 = new Complex2 ();

[Link] = ([Link] + [Link]);

[Link] = ([Link] + [Link]);

return c3;

public Complex2 Sub(Complex2 c1, Complex2 c2)

Complex2 c3 = new Complex2 ();

[Link] = ([Link] - [Link]);

[Link] =([Link] -[Link]);

return c3;

public Complex2 Mult(Complex2 c1, Complex2 c2)


{

Complex2 c3 = new Complex2 ();

[Link] =([Link]*[Link] - [Link]*[Link]);

[Link] = ([Link]*[Link]+[Link]*[Link]);

return c3;

public Complex2 Divide(Complex2 c1,Complex2 c2)

Complex2 c3 = new Complex2 ();

[Link] = [Link]*[Link] + [Link]*[Link];

[Link] = ([Link]*[Link]+[Link]*[Link]);

[Link] = ([Link]*[Link] - [Link]*[Link]);

return c3;

Complex3
public class Complex3 {

private float real;

private float img;

private float eno;

Complex3()

real=0;

img=0;

Complex3(float real, float img)

[Link] =real;

[Link] = img;
}

public void Add(Complex3 c1)

[Link] = ([Link] + [Link]);

[Link] = ([Link] + [Link]);

[Link]([Link]+" "+[Link]+"i");

public void Sub(Complex3 c1)

[Link] = ([Link] - [Link]);

[Link] =([Link] -[Link]);

[Link]([Link]+" "+[Link]+"i");

public void Mult(Complex3 c1)

[Link] =([Link]*[Link] - [Link]*[Link]);

[Link] = ([Link]*[Link]+[Link]*[Link]);

[Link]([Link]+" "+[Link]+"i");

public void Divide(Complex3 c1)

[Link] = [Link]*[Link] + [Link]*[Link];

[Link] = ([Link]*[Link]+[Link]*[Link]);

[Link] = ([Link]*[Link] - [Link]*[Link]);


[Link]("("+[Link]+" "+[Link]+"i)/"+[Link]);

public void Reset() {

real=0;

img=0;

Driver
import [Link];

public class Driver {

public static void main(String[] args) {

int ch=0;

float num1,num2,num3,num4;

Scanner in = new Scanner([Link]);

[Link]("Enter first real number");

num1 = [Link]();

[Link]("Enter first imaginary number");

num2 = [Link]();

Complex c1 = new Complex(num1,num2);

[Link]("Enter second real number");

num3 = [Link]();

[Link]("Enter second imaginary number");

num4 = [Link]();

Complex c2 = new Complex(num3,num4);

Complex c3 = new Complex ();

do
{

[Link]("\n -------MENU----------");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("Please enter your choice ");

ch = [Link]();

switch (ch)

case 1:

[Link](c1, c2);

break;

case 2:

[Link](c1,c2);

break;

case 3:

[Link](c1, c2);

break;

case 4:

[Link](c1, c2);

break;

case 5:

[Link]("Exiting");

return;

while (ch!=5);
}

Driver1
import [Link];

public class Driver1 {

public static void main(String[] args) {

int ch=0;

float num1,num2,num3,num4;

Scanner in = new Scanner([Link]);

[Link]("Enter first real number");

num1 = [Link]();

[Link]("Enter first imaginary number");

num2 = [Link]();

Complex1 c1 = new Complex1(num1,num2);

[Link]("Enter second real number");

num3 = [Link]();

[Link]("Enter second imaginary number");

num4 = [Link]();

Complex1 c2 = new Complex1(num3,num4);

Complex1 c3 = new Complex1 ();

do

[Link]("\n -------MENU----------");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("Please enter your choice ");

ch = [Link]();
switch (ch)

case 1:

[Link](c1, c2);

break;

case 2:

[Link](c1,c2);

break;

case 3:

[Link](c1, c2);

break;

case 4:

[Link](c1, c2);

break;

case 5:

[Link]("Exiting");

return;

while (ch!=5);

Driver2
import [Link];

public class Driver2 {

public static void main(String[] args) {

int ch=0;

float num1,num2,num3,num4;
Scanner in = new Scanner([Link]);

[Link]("Enter first real number");

num1 = [Link]();

[Link]("Enter first imaginary number");

num2 = [Link]();

Complex2 c1 = new Complex2(num1,num2);

[Link]("Enter second real number");

num3 = [Link]();

[Link]("Enter second imaginary number");

num4 = [Link]();

Complex2 c2 = new Complex2(num3,num4);

Complex2 c3 = new Complex2 ();

do

[Link]("\n -------MENU----------");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("Please enter your choice ");

ch = [Link]();

switch (ch)

case 1:

c3=[Link](c1, c2);

[Link]([Link]+" "+[Link]+"i");

break;

case 2:

c3=[Link](c1,c2);

[Link]([Link]+" "+[Link]+"i");
break;

case 3:

c3=[Link](c1, c2);

[Link]([Link]+" "+[Link]+"i");

break;

case 4:

c3=[Link](c1, c2);

[Link]("("+[Link]+" "+[Link]+"i)/"+[Link]);

break;

case 5:

[Link]("Exiting");

return;

while (ch!=5);

Driver3
import [Link];

public class Driver3 {

public static void main(String[] args) {

int ch=0;

float num1,num2,num3,num4;

Scanner in = new Scanner([Link]);

[Link]("Enter first real number");

num1 = [Link]();

[Link]("Enter first imaginary number");

num2 = [Link]();
[Link]("Enter second real number");

num3 = [Link]();

[Link]("Enter second imaginary number");

num4 = [Link]();

do

Complex3 c1 = new Complex3(num1,num2);

Complex3 c2 = new Complex3(num3,num4);

[Link]("\n -------MENU----------");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("[Link]");

[Link]("Please enter your choice ");

ch = [Link]();

switch (ch)

case 1:

[Link](c1);

break;

case 2:

[Link](c1);

break;

case 3:

[Link](c1);

break;

case 4:

[Link](c1);

break;

case 5:
[Link]("Exiting");

return;

while (ch!=5);

You might also like