Java code that needs to be coded-complex number class

Assignment Help JAVA Programming
Reference no: EM13286806

Just a Java Code that needs to be coded. Your given the design, just needs the methods and such to be fixed. This is for a Complex Number class.

/**

* ComplexNumber models a complex number expressed

* in rectangular form (real and imaginary parts).

* It is an <em>immutable</em> object.

*

*/

public class ComplexNumber {

//Instance variable declarations

/**

* Construct a ComplexNumber given its

* real and imaginary parts.

* @param re The real component

* @param im The imaginary component

*/

public ComplexNumber(double re, double im) {

//Initialize the instance variables

}

/**

* Returns the real component.

* @return the real

*/

public double getReal() {

return 0.0; //A stub: to be fixed

}

/**

* Returns the imaginary component.

* @return the imaginary

*/

public double getImaginary() {

return 0.0; //A stub: to be fixed

}

/**

* Returns a new ComplexNumber number that is

* the negative of <em>this</em>. Note: the

* original ComplexNumber is <b>NOT</b>

* modified.

* @return -this

*/

public ComplexNumber negate() {

return null; //A stub: to be fixed

}

/**

* Returns a new ComplexNumber that is the

* sum of <em>this</em> and <em>z</em>.

* Note: the original ComplexNumber is

* <b>NOT</b> modified.

* @param z

* @return this + z

*/

public ComplexNumber add(ComplexNumber z) {

return null; //A stub: to be fixed

}

/**

* Returns a new ComplexNumber that is the

* difference of <em>this</em> and <em>z</em>.

* Note: the original ComplexNumber is

* <b>NOT</b> modified.

* @param z

* @return this + z

*/

public ComplexNumber subtract(ComplexNumber z) {

return null; //A stub: to be fixed

}

/**

* Returns a new ComplexNumber that is the

* product of <em>this</em> and <em>z</em>.

* Note: the original ComplexNumber is

* <b>NOT</b> modified.

* @param z

* @return this * z

*/

public ComplexNumber multiply(ComplexNumber z) {

return null; //A stub: to be fixed

}

/**

* Returns a new ComplexNumber that is

* the reciprocal of <em>this</em>.

* Note: the original ComplexNumber is

* <b>NOT</b> modified.

* @return 1.0 / this

*/

public ComplexNumber reciprocal() {

return null; //A stub: to be fixed

}

/**

* Returns a new ComplexNumber that is

* <em>this</em> divided by <em>z</em>.

* Note: the original ComplexNumber is

* <b>NOT</b> modified.

* @param z

* @return this / z

*/

public ComplexNumber divide(ComplexNumber z) {

return null; //A stub: to be fixed

}

/**

* Returns a String representation of

* <em>this</em> in the format:

* <pre>

* real +-(optional) i imaginary

* </pre>

* If the imaginary part is zero, only the

* real part is converted to a String.

* A "+" or "-" is placed between the real

* and imaginary parts depending on the

* the sign of the imagrinary part.

* <p>

* Examples:

* <pre>

* ..println(new ComplexNumber(0,0); -> "0.0"

* ..println(new ComplexNumber(1,1); -> "1.0 + i1.0"

* ..println(new ComplexNumber(1,-1); -> "1.0 - i1.0"

* </pre>

* @return the String representation.

*/

@Override

public String toString() {

//DO NOT MODIFY THIS CODE!

String str = "" + this.getReal();

if (this.getImaginary() == 0.0) {

return str;

}

if (this.getImaginary() > 0) {

return str + " + i" + this.getImaginary();

} else {

return str + " - i" + -this.getImaginary();

}

}

}

Reference no: EM13286806

Questions Cloud

What ways can vulnerable inmates be protected : What ways can vulnerable inmates be protected? Why are classification and housing assignments so critical to these populations?
Critics of american often that teacher''s unions represent : Which organization has proposed a set of standards for both elementary level and secondary-level teachers? According to the latest info.,  teachers will be most needed in which of the following areas: Critics of American often argue that teacher's un..
Morgellons disease is delusional : Why do some scientists say that Morgellons disease is delusional? When there have been fibers extracted from patients that cannot be identified? Isn't that physical proof that something is affecting these people physically?
Mutant bacterium-synthesize the amino acid tyrosine : Consider a mutant bacterium you have isolated which is unable to synthesize the amino acid tyrosine. You grow it in the presence of a chemical mutagen and isolate a single revertant, which is now able to grow in the absence of tyrosine
Java code that needs to be coded-complex number class : Just a Java Code that needs to be coded. Your given the design, just needs the methods and such to be fixed. This is for a Complex Number class.
What were the health challenges of the early culture : What were the health challenges of the Early culture ( the Eras of Egyptians, Greeks, Romans)? What were the factors/ beliefs, knowledge or lack of knowledge, etc. that influenced these health problems?
Enzymatic denaturation is a strong function of temperature : Increasing the temperature from 40 to 50 C increases kd by 32 fold. What is the value of Ed? Also, if the value of kd at 40C is 0.1 min-1, what is the percentage decrease in enzyme concentration during the enzymatic reaction carried out at 37C for 10..
Explain the ion movement that occur in each phase : List the phases of the cardiac muscle action potential and explain the ion movement that occur in each phase
Hiring a marketing firm : What considerations should an administrator take into account when hiring a marketing firm? How would you choose a company to help you market your practice?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java program to read sequences of integers

Write a Java program to read sequences of integers from a text file, build a binary search tree for each sequence by inserting numbers in the sequence one after another into the search tree, and plot a picture of the finished tree.

  Write the method in java

2.char mostOftenIn(String s) that for a given string s, returns the character that occurs most often in s.

  Create an employee class.

Create an Employee class. Items to include as data members are employee number, name, date of hire, job description, department, and monthly salary.

  Calculate the optimal position of the large pipeline

Your task is to calculate the optimal position (on the y-axis) of the large pipeline, so that the total length of all smaller pipelines is shortest

  Difference between the two following statements

What exactly is the difference between the two following statements and which is preferred, please provide details: 1) frame.setSize(400, 300); // Set JFrame Size

  Write java program to enter number of marks

Write a java program called AverageMark.java. This program should allow the user to enter any number of marks and then display the minimum, maximum & average mark.

  Write a program to test your class definition

Do not define an input method. The only method that can set the counter is the one that sets it to zero. Write a program to test your class definition.

  Accepts a string as its parameter and returns an integer

Write a method in java named secondHalfLetters that accepts a string as its parameter and returns an integer representing how many of letters in the string come from the second half of the alphabet

  Write a program in java that simulates a simple line editor

Write a program in Java that simulates a simple line editor which supports the following operations

  Determine the type of moped

Write a driver class called MopedRental. This class should perform the following: asks the user to enter the size of the moped, the day of the week and the number of hours rented, creates the Moped object, based on the size, and displays the input..

  One acre of land is equivalent to

One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of square feet in a tract of land with 3.5acres.

  Use a loop to allow a user to enter a series of numbers

Use a loop to allow a user to enter a series of numbers and then print out the series of numbers when the user is done. The user stops the lseries program by entering -1 (or any negative number).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd