subject

Create a Rational number class in Java using the same style as the Complex number class created in class.(The in class example code is below) That is, implement the following methods:constructoradd submuldivtoStringYou must also provide a Main class and main method to fully test your Rational number class. Example code:public class Main { public static void main(String[] args) { Complex a = new Complex(2.0, 3.0); Complex b = new Complex(1.0, 2.0); System. out. println(a + " + " + b + " = " + a. add(b)); System. out. println(a + " - " + b + " = " + a. sub(b)); System. out. println(a + " * " + b + " = " + a. mul(b)); System. out. println(a + " / " + b + " = " + a. div(b)); }}class Complex { public Complex(double re, double im) { real = re; imag = im; } public Complex add(Complex o) { return new Complex(real + o. real, imag + o. imag); } private Complex conjugate() { return new Complex(real, -imag); } public Complex div(Complex o) { Complex top = mul(o. conjugate()); Complex bot = o. mul(o. conjugate()); return new Complex(top. real / bot. real, top. imag / bot. real); } public Complex mul(Complex o) { return new Complex(real * o. real - imag * o. imag, real * o. imag + imag * o. real); } public Complex sub(Complex o) { return new Complex(real - o. real, imag - o. imag); } public String toString() { return "(" + real + " + " + imag + "i)"; } private double real; private double imag;}

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 18:20, dinosaur10
Geneva’s manager would like to see some additional information to make sales decisions. enter a formula in cell j4 using the if function to it whether or not the item beaded earrings should go on sale. it will go on sale if its current sales rank (in cell g4) is 8th or lower. (hint: if the cell value is greater than or equal to 8, it will go on sale.)if this condition is true, the item will go on sale. (hint: the if_true value should be “yes”.)if this condition is false, the item doesn’t need to go on sale. (hint: the if_false value should be “-”.)copy the formula created in cell j4 to the range j5: j14
Answers: 2
image
Computers and Technology, 22.06.2019 22:30, raiapowell
I'll mark brainliest if answered right! with which feature or menu option of a word processing program can you make an image like this? you can get this image using the option of a word processing program.
Answers: 1
image
Computers and Technology, 23.06.2019 22:30, reaganphelps3
What would be the address of the cell, which is at the intersection of the second row and the third column in a worksheet?
Answers: 1
image
Computers and Technology, 24.06.2019 10:00, zlittleton2008
Which feature of a blog to restore and retrieve older post
Answers: 3
You know the right answer?
Create a Rational number class in Java using the same style as the Complex number class created in c...

Questions in other subjects:

Konu
Mathematics, 12.04.2020 23:47
Konu
Mathematics, 12.04.2020 23:47
Konu
Computers and Technology, 12.04.2020 23:47
Konu
Chemistry, 12.04.2020 23:48