Complex Language/Type: Java classes Comparable compare To interfaces implementing instance methods Related Links: Author: Complex.java Marty...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Complex Language/Type: Java classes Comparable compare To interfaces implementing instance methods Related Links: Author: Complex.java Marty Stepp Suppose that a class Complex has been defined for storing complex numbers. In mathematics, complex numbers are those that can be written as (x + y) where x and y are real numbers and i is the square root of -1. In other words, complex numbers have a real part (x) and an imaginary part (y). The class includes the following members: Name private double x private double y public Complex(double x, double y) public double getReal() public double getImaginary() public double abs() public string tostring() public complex add(Complex other) real part imaginary part Description constructs a complex number x + y*i returns the real part of the number returns the imaginary part of the number returns the absolute value of the number returns a String representation of the number returns the result of adding another complex number to this one public complex subtract (Complex other) | returns the result of subtracting another complex number from this one Your task is to modify the class to be Comparable by adding an appropriate compareTo method. Complex objects should be compared using absolute value with smaller absolute values considered "less" than numbers of higher absolute value. The absolute value of a complex number is defined to be the square root of the sum of the squares of x and y. Complex Language/Type: Java classes Comparable compare To interfaces implementing instance methods Related Links: Author: Complex.java Marty Stepp Suppose that a class Complex has been defined for storing complex numbers. In mathematics, complex numbers are those that can be written as (x + y) where x and y are real numbers and i is the square root of -1. In other words, complex numbers have a real part (x) and an imaginary part (y). The class includes the following members: Name private double x private double y public Complex(double x, double y) public double getReal() public double getImaginary() public double abs() public string tostring() public complex add(Complex other) real part imaginary part Description constructs a complex number x + y*i returns the real part of the number returns the imaginary part of the number returns the absolute value of the number returns a String representation of the number returns the result of adding another complex number to this one public complex subtract (Complex other) | returns the result of subtracting another complex number from this one Your task is to modify the class to be Comparable by adding an appropriate compareTo method. Complex objects should be compared using absolute value with smaller absolute values considered "less" than numbers of higher absolute value. The absolute value of a complex number is defined to be the square root of the sum of the squares of x and y.
Expert Answer:
Posted Date:
Students also viewed these programming questions
-
EBV Infection Smoking (exposure) Incidence per 100,000 (no decimal) Attributable Risk per 100,000 (no decimal) Relative Risk per 100,000 (two decimals) Negative No 5 0 1.00 Yes 8 3 1.60 Positive No...
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
Jay Bhattacharya and Kate Bundorf of Stanford University have found evidence that people who are obese and who work for firms that provide health insurance receive lower wages than workers at those...
-
Two manufacturers of table-tennis balls have agreed that the quality of their products can be measured by the height to which the balls rebound. A test is arranged, the balls are dropped from a...
-
How are financial ratios used in decision making? a. They eliminate uncertainty regarding cash flows. b. They can be used as a substitute for consulting financial statements. C. They are only used in...
-
On March 10, Barnes, Inc., declared a \(\$ 3,700\) account receivable from Lamas Company as uncollectible and wrote off the account. On November 18, Barnes received a \(\$ 1,600\) payment on the...
-
Salem Corp. contracted for a specialized production machine from Quindo Industries, a tool company. The contract specified a price equal to production cost plus 15% of production cost. A sales...
-
Listed below are the measured radiation emissions (in W/kg) corresponding to cell phones: A, B, C, D, E, F, G, H, I, J, and K respectively. The media often present reports about the dangers of cell...
-
Seacera Tiles Corp is considering the following average risk projects for its next Seacera has 10,000 bonds outstanding that were issued for 30 years ten years ago at a par value of RM1,000.00 and a...
-
Which of the following is not a part of the audit risk model? a. Inherent risk. b. Control risk. c. Materiality risk. d. Detection risk.
-
Because much of an auditor's work involves an audit of various client financial records, why does the auditor's report state that he or she has audited the financial statements rather than the...
-
Which of the following is a correct statement? a. There is an inverse relationship between risk levels and the amount of necessary audit effort. b. There is a direct relationship between risk levels...
-
List the individual financial statements normally included in a complete set and indicate which phrase of the opinion paragraph applies to each statement.
-
Ages of dogs at a rescue facility. In Exercises 714, determine whether the data are qualitative or quantitative. Explain your reasoning.
-
Solve the following simultaneous equations by using the inverse matrix method. x+2y+z = 4 %3D 3x- 4y-2z 2 5x+3y+5z = -1 %3D
-
As economic conditions change, how do banks adjust their asset portfolio?
-
Donna Ahern is the sole stockholder and operator of Omega, a motivational consult- ing business. At the end of its accounting period, December 31, 2009, Omega has assets of \($760,000\) and...
-
a. A vacant lot acquired for \($150,000\) is sold for \($290,000\) in cash. What is the effect of the sale on the total amount of the seller's (1) assets, (2) liabilities, and (3) stock- holders'...
-
The following selected transactions were completed by Lindbergh Delivery Service during October: 1. Received cash from issuing capital stock, \($75,000\). 2. Paid rent for October, \($4,200\). 3....
Study smarter with the SolutionInn App