Question
Hi there, my professor gave us a classwork about classes. He have us a complex number class or complex number class demo and he told
Hi there, my professor gave us a classwork about classes. He have us a complex number class or complex number class demo and he told us to finish it by adding strings and classes. In short he gave us-
ComplexNumber cn1 = new ComplexNumber (4, 5);
ComplexNumber cn2 = new ComplexNumber (3, -2);
ComplexNumber cn3, cn4, cn5, cn6, cn7;
System.out.println ("First ComplexNumber number: " + cn1);
System.out.println ("Second ComplexNumber number: " + cn2);
if (cn1.equals(cn2))
System.out.println ("cn1 and cn2 are equal.");
else
System.out.println ("cn1 and cn2 are NOT equal.");
cn4 = cn1.add(cn2);
cn5 = cn1.subtract(cn2);
cn6 = cn1.multiply(cn2);
cn7 = cn1.divide(cn2);
System.out.println ("cn1 + cn2: " + cn4);
System.out.println ("cn1 - cn2: " + cn5);
System.out.println ("cn1 * cn2: " + cn6);
System.out.println ("cn1 / cn2: " + cn7);
}
}
As you can see in the above code he wants us to create complex number class and add some codes in it. I would recommend you to copy and paste this code in your compiler and see what the code or what the new class needs to give the outputs in above code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started