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
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