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 01:50
A.) generate scaffolding to create database for your application. develop all the entities identified in assignment #2. add any additional that may be identified later. b.) add data validation rules to the models that are appropriate for your application and data. c.) create links for each scaffold in the header section. part 2: application updates [30 points] a.) add two additional views to the "home" controller you created in assignment #1. b.) the two views should be named as “privacy" and "". c.) link the two newly created views in the footer section. hint: you would need to modify the “home" controller definition and create “privacy.html.erb" and “.html.erb" files in appropriate locations.
Answers: 3
question
Computers and Technology, 22.06.2019 11:00
When working with a team you should always do the following, except? question 3 options: be dependable and trustworthy be sensitive to others feelings do your fair share critique members of the group
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
The place where the extended axis of the earth would touch the celestial sphere is called the celestial
Answers: 1
question
Computers and Technology, 24.06.2019 03:30
It is not necessary to develop strategies to separate good information and bad information on the internet. true or false
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
History, 16.12.2020 22:10
question
Mathematics, 16.12.2020 22:10
question
Mathematics, 16.12.2020 22:10
question
Chemistry, 16.12.2020 22:10
question
Mathematics, 16.12.2020 22:10
question
Mathematics, 16.12.2020 22:10
Questions on the website: 13722359