Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java Writing class ComplexNumber: First, the class that defines a complex number: See below for a refresher on complex numbers. Your class will have

In Java

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Writing class ComplexNumber: First, the class that defines a complex number: See below for a refresher on complex numbers. Your class will have a constructor that takes two floats as parameters. The two floats will represent the a and b parts of the complex number. Your class will have eight methods. Four of the methods will implement complex number addition, subtraction, multiplication, and division. Each will take a parameter: the other complex number to be added to, subtracted from, multiplied by, or divided into this complex number. Each of these methods will return a new complex number that is the result of the operation. You will also need two getter methods to return the a and b parts of the complex number. You will provide an equals method by overriding Object's equals method. The last method will be a toString method that will return a string representing the complex number. Here is a sketch of the class with the method for addition completed for you (You're welcome!). public class ComplexNumber // The instance variables a and b representing // the real parts of the complex number private float a; private float b; public ComplexNumber(float _a, float _b) { /* You fill in here! *7 } public ComplexNumber add(ComplexNumber otherNumber) { ComplexNumber newComplex; float newA = a + otherNumber.getA(); float newB = b + otherNumber.getB(); newComplex = new ComplexNumber(new, newB); return newComplex; } //... /* You will fill in the rest of the methods */ //... Writing the JUnit Tester In a separate file, ComplexNumberTests.java, implement a JUnitTester for your ComplexNumber class using JUnit 4. You should provide at least one @Test method for each of the public methods in ComplexNumber. Each test method should verify the correctness of the method it is testing using multiple ComplexNumber instances as input. Compile and run the test class (using org.junit.runner.JUnitCore) to verify that all your tests pass. Be sure to test for a wide variety of input combinations to ensure adequate testing. Take a look at the JUnit documentation online to discover new interesting testing techniques. Tip: when testing your program to make sure your calculations are correct, use www.wolframalpha.com to verify your calculations. About Complex Numbers: Recall that a complex number is a number a + bi where i = -1 and a and b are real numbers. To add two complex numbers: (a + bi)+(c + di) = (a + c)+(b + d)i Similarly, to subtract two complex numbers: (a + bi) - (c + di) = (a - c)+(b-d)i To multiply two complex numbers: (a + bi)(c + di) = (ac bd) + (bc + ad)i Finally, to divide two complex numbers: a + bi C + di ac + bd c2 + d2 bc ad + 1c2 + d2

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions