Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

=+9. Think about a campaign direction.

Answered: 1 week ago

Question

=+Who is the audience?

Answered: 1 week ago