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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:00
You need a reliable network for about twenty-five computers that will be distributed across a large building. it is important that the network be relatively cheap. which topology should you use?
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
Which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
question
Computers and Technology, 23.06.2019 06:00
Which statement is true of web-based social media? a.they allow consumers to interact with and update content. b.they cannot be updated easily, as compared to print media. c.they are expensive to produce and maintain, as compared to print and television. d.they can exist independent of the internet.
Answers: 1
question
Computers and Technology, 24.06.2019 00:40
What is the error in the following pseudocode? module main() call raisetopower(2, 1.5) end module module raisetopower(real value, integer power) declare real result set result = value^power display result end module
Answers: 1
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
question
Business, 27.07.2019 03:50
question
History, 27.07.2019 03:50
Questions on the website: 13722361