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

  A program that reads a four-digit number from the keyb

Write a program that reads a four-digit number from the keyboard as a string and then converts it into decimal. For example, if the input is 1100, the output should be 12. Hint: Break the string into characters and then convert each character to a va..

  Write method called median that accepts an array of integer

Write a method called median that accepts an array of integers as its parameter and returns the median of the numbers in the array.

  Write java program to store values retrieved from user-array

Write a Java program named Arrays6_2GF.java Use an array to store values retrieved from user input. The number of integers to be entered (the length of the array )should also be retrieved through user input.

  Productexception class whose constructor

Create a ProductException class whose constructor receives a String that consists of a product number and price. Save the file as ProductException.java. Create a Product class with two fields, productNum and price. The Product constructor requires va..

  Write a program that prompts the user for a start date

write a program that prompts the user for a start date and an end date and then prints all of the dates between them (inclusive), with seven tab-separated dates on each line.

  Write complete java program to read from keyboard

Write complete Java program to read, from keyboard, a student's first and last name and six grades. It will display on screen last name then first letter of first name with a period.

  Modify the book class to accommodate multiple authors

modify the Book class to accommodate multiple authors using one of the components from the Java Collection Framework.

  Simple java program that implements some basic file

Your code will prompt the user to enter a file name. If this file does not exist the program will produce an error message and exit. Otherwise the program will open the file and read a line from the file, reverse the line, and then print the line to ..

  Create a java class called samearraysexception

Create a Java class called SameArraysException that extends the Exception class.

  Alter the prototype form page by javascript function

Alter the prototype form page so that when JavaScript function has verified that all the required fields have been filled, cookie is added to user's computer.

  Method splitstack that takes a stack

Write a method splitStack that takes a stack of integers as a parameter and splits it into negatives and non-negatives. The numbers in the stack should be rearranged so that all the negatives appear on the bottom of the stack and all the non-negat..

  Reimplement the labeledpoint class of exercise

Reimplement the LabeledPoint class of Exercise P9.12 by storing the location in a java.awt.Point object. Your toString method should invoke the toString method of the Point class.

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