Question
Hi! I need help with JUnit since this is my first encounter with it. This is what I have to do: 1. Use assertNotNull() to
Hi! I need help with JUnit since this is my first encounter with it. This is what I have to do:
1. Use assertNotNull() to test the Complex(double, double) constructor
2. Use assertEquals(double, double, double) to test if getReal() returns the correct value set using the Complex(int, int) constructor
3. Use assertEquals(double, double, double) to test if setReal() correctly resets the value set using the Complex(double, double) constructor
4. Use the no-arg Complex() constructor, and then use the real and imaginary setters to set new integer values. Then use assertTrue(boolean) to test the validity of your newly-added equals(int, int) method
5. Using assertTrue(boolean), test that two Complex numbers created using the Complex(String[]) constructor and the Complex(String, String) constructor give the correct result using the multiply() method. Use equals(Complex) to compare the actual and expected result
6. Divide two Complex numbers and use the result to test your equals(double expected, double actual, double delta) method, with delta = .0000001
And this is my class code
And here is my attempt of doing 1, 2 and 3. It's a mess and it's horrible, I know.
Please take the time to explain stuff so I will be able to understand it more. Thanks for the help!
eclipse-workspace-CS18284-Lab04/src/cst8284/calculator/Complexava-Eclipse File Edit Scurce Refatr Navigate Search Preject Rur Winduw Help 1 package cst8284.calculator 3 public class Conplex \ private double real = e; privata doublo ina // Complex ranstructor that takrs in a single string, r.E- 2-4i. 9 public Conplex(String Str this(cstr.split"?V)"): splits cstr ator into an array of strings having two elenents The first elenrnt of thr resultant array wil1 he the rral portion, while the second is the imaginary porLio This array is passed to Lhe riext constructor 12 13 14 Complex constructor that takes in an array of two strings fron the above constructor 17 1 public Conplex(String] cStr) 19 this(cStr[el, cstr[11); 21 23 Conplex ranstructor that takrs two separate strings as parameters, r.g. "" and Ai" 24 public Conplex(Strirng r, String i) this(Integer parseint(r), Integer parselnt(i.replace"))) 06 Complex ronstructor that takrs in tun ints as paraneters, .e-2 and- public Conplex(int r, int i) 31 this (double)r, (double)i); 34 // Complex ranstructor that takes in tun ints and stares then as floats, r.E- as ).e and .4. 6 public Conplex(double , double i) 3/ this.setReal(r); this-set Tmng(1 ) ; 11 idefault Complex constructorg it should rhain autonatically 42 public Conplex)this(,8); 45 public double getReal Smart Insert 71:107 eclipse-workspace-CS18284-Lab04/src/cst8284/calculator/Complexava-Eclipse File Edit Scurce Refatr Navigate Search Preject Rur Winduw Help 1 package cst8284.calculator 3 public class Conplex \ private double real = e; privata doublo ina // Complex ranstructor that takrs in a single string, r.E- 2-4i. 9 public Conplex(String Str this(cstr.split"?V)"): splits cstr ator into an array of strings having two elenents The first elenrnt of thr resultant array wil1 he the rral portion, while the second is the imaginary porLio This array is passed to Lhe riext constructor 12 13 14 Complex constructor that takes in an array of two strings fron the above constructor 17 1 public Conplex(String] cStr) 19 this(cStr[el, cstr[11); 21 23 Conplex ranstructor that takrs two separate strings as parameters, r.g. "" and Ai" 24 public Conplex(Strirng r, String i) this(Integer parseint(r), Integer parselnt(i.replace"))) 06 Complex ronstructor that takrs in tun ints as paraneters, .e-2 and- public Conplex(int r, int i) 31 this (double)r, (double)i); 34 // Complex ranstructor that takes in tun ints and stares then as floats, r.E- as ).e and .4. 6 public Conplex(double , double i) 3/ this.setReal(r); this-set Tmng(1 ) ; 11 idefault Complex constructorg it should rhain autonatically 42 public Conplex)this(,8); 45 public double getReal Smart Insert 71:107Step 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