Complex Number Manipulation

download Complex Number Manipulation

of 3

Transcript of Complex Number Manipulation

  • 8/12/2019 Complex Number Manipulation

    1/3

    COMPLEX NUMBER MANIPULATION

    public class ComplexNumber

    {private int a;private int b;public ComplexNumber()

    {12}public ComplexNumber(int a, int b){

    this.a =a;this.b=b;}

    public Strin etComplex!alue(){i"(this.b # $){return

    a%&&%b%&i&;}else{return a%&%&%b%&i&;}}public static Strin

    a''ition(ComplexNumber num1, ComplexNumber num2){int

    a1= num1.a%num2.a;int b1= num1.b%num2.b;i"(b1#$){return

    a1%&&%b1%&i&;} else {return a1%&%&%b1%&i&;}}public static

    Strin substraction(ComplexNumber num1, ComplexNumber

    num2){int a1= num1.anum2.a;int b1= num1.b

    num2.b;i"(b1#$){1

    return a1%&&%b1%&i&;} else {return

    a1%&%&%b1%&i&;}}public static Strin

    multiplication(ComplexNumber num1, ComplexNumbernum2){int a1= num1.a*num2.a;int b1= num1.b*num2.b;int vi1

    = num1.a * num2.b;int vi2 = num2.a * num1.b;int

    vi;vi=vi1%vi2;i"(vi#$){return a1b1%&&%vi%&i&;} else {return

    a1b1%&%&%vi%&i&;}}public static voi' main(Strin ars+)

    {ComplexNumber com1 = ne- ComplexNumber(2,

    );ComplexNumber com2 = ne- ComplexNumber(,

    /);S0stem.out.println(com1.etComplex!alue());S0stem.out.println(com2.etComplex!alue());S0stem.out.println(&

    ''ition o" both Complex Numbers

    are &%ComplexNumber.a''ition(com1,com2));S0stem.out.pri

  • 8/12/2019 Complex Number Manipulation

    2/3

    ntln(&Substraction o" both Complex Numbers

    are &%ComplexNumber.substraction(com1,com2));1

    S0stem.out.println(&3ultiplication o" both Complex

    Numbersare &%ComplexNumber.multiplication(com1,com2));}}

    OUTPUT:

    456avaexecute78avac

    ComplexNumber.8ava456avaexecute78ava ComplexNumber2

    i/i''ition o" both Complex Numbers are 9

    :iSubstraction o" both Complex Numbers are

    2%2i3ultiplication o" both Complex Numbers are %22i1/

  • 8/12/2019 Complex Number Manipulation

    3/3

    exception A@nvali'B./.se Doolean t0pe "or metho' to

    return the values as either true or "alse.9.Chec? the

    values "or month an' values "or 'a0 usin i"

    loops..Chec? the 0ear usin i" loop -hether it isleap 0ear or not.:.>e"ine metho's is"ter() an'

    isDe"ore() in proram.E.>e"ine metho' compareo()

    to compare the 'ate.1$.@n main() create ob8ect to'a0 an'

    ive current 'ate as value "or constructor"iel's11.Call the

    all metho's to 'ispla0 the 'ates.

    DATE CLASS SIMILAR TO JAVA.UTIL PACKAGE

    public class >ate {private "inal int month;private "inal int

    'a0;1