Question: This is java code. pleas use java eclipace only when do this code. 1, Create JUnit Test File for the code below for (class Complex).

This is java code. pleas use java eclipace only when do this code.

1, Create JUnit Test File for the code below for ("class Complex").

2. Create Comparable.java for the code below for ("class Complex").

2. Create UML digram ("class Complex").

package problem1;

public class Complex { private double re; private double im; //****************************** // Constructor 1 public Complex(double real, double imag) { re = real; im = imag; } // Constructor 2 public Complex(double real) { re = real; im = 0; } // Constructor 3 public Complex() { re = 0; im = 0; } public double abs() { return Math.sqrt(re * re + im * im); } //********************************** //get method for real part public double getRe() { return this.re; } public void setRe(double re) { this.re=re; } //get method for imaginary part public double getIm() { return this.im; } public void setIm(double im) { this.im=im; } //***************************************** // Setter method public void setreAndim(double re, double im) { this.setRe(re); this.setIm(im); } @Override public String toString() { return "Values:("+ re +")+("+im+"i)"; } public Complex plus(Complex temp) { Complex result=new Complex(); result.re=this.getRe()+temp.getRe(); result.im=this.getIm()+temp.getIm(); return result; } public Complex minus(Complex temp) { Complex result=new Complex(); result.re=this.getRe()-temp.getRe(); result.im=this.getIm()-temp.getIm(); return result; } public Complex times(Complex temp) { Complex result=new Complex(); result.re=(this.getRe()*temp.getRe())-(this.getIm()*temp.getIm()); result.im=(this.getRe()*temp.getIm())+(this.getIm()*temp.getRe()); return result; } public Complex division(Complex temp) { Complex result=new Complex(); result.re=(((this.getRe()*temp.getRe())+(this.getIm()*temp.getIm()))/(Math.pow(temp.getRe(),2)+ Math.pow(temp.getIm(),2))); result.im=(((this.getRe()*temp.getIm())-(this.getIm()*temp.getRe()))/(Math.pow(temp.getRe(),2)+ Math.pow(temp.getIm(),2))); return result; } //****************************** public static void main(String[] args) { Complex complex=new Complex(); Complex complex1=new Complex(1,4); Complex complex2=new Complex(3,-5); System.out.println("complex" + complex); System.out.println("complex1" + complex1); System.out.println("complex2" + complex2); System.out.println("Plus" + complex1.plus(complex2)); System.out.println("Minus" + complex1.minus(complex2)); System.out.println("Times" + complex1.times(complex2)); System.out.println("Division" + complex1.division(complex2)); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!