Computers and Technology

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;}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:30, yudayang2012pa9u8p
Consider the following statements: #include #include class temporary { private: string description; double first; double second; public: temporary(string = "", double = 0.0, double = 0.0); void set(string, double, double); double manipulate(); void get(string& , double& , double& ); void setdescription(string); void setfirst(double); void setsecond(double); }; write the definition of the member function set() so that the instance variables are set according to the parameters. write the definition of the constructor so that it initializes the instance variables using the function set() write the definition of the member function manipulate() that returns a decimal number (double) as follows: if the value of description is "rectangle", it returns first * second if the value of description is "circle" it returns the area of a circle with radius first if the value of description is "cylinder" it returns the volume of a cylinder with radius first and height second. hint: the volume of a cylinder is simply the area of the circle at the base times the height. if the value of description is "sphere" it returns the volume of the sphere with radius first. otherwise it returns -1.0;
Answers: 1
image
Computers and Technology, 22.06.2019 14:40, Kathryn014
You are working with a professional edition organization. they wish to install the expense tracker which requires the use of 4 custom tabs, 3 custom objects, and one custom app. if the company is already using 4 applications, 36 custom objects, and 7 custom tabs, what will happen when they try to install expense tracker?
Answers: 1
image
Computers and Technology, 22.06.2019 19:20, mahaleyrenee1195
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 2
image
Computers and Technology, 23.06.2019 22:30, delawdermia27
The output voltage of a power supply is assumed to be normally distributed. sixteen observations are taken at random on voltage are as follows: 10.35, 9.30, 10.00, 9.96, 11.65, 12.00, 11.25, 9.58, 11.54, 9.95, 10.28, 8.37, 10.44, 9.25, 9.38, and 10.85
Answers: 1
Do you know the correct answer?
Create a Rational number class in Java using the same style as the Complex number class created in c...

Questions in other subjects: