i) Create a class called Complex for performing arithmetic with complex numbers.
ii) Write a driver program to test your class.
Complex numbers have the form
realPart+imaginaryPart *i
Where i is:
√-1
Use floating point variables to represent the private data of the class. Provide a constructor method that enables an object of this class to be initialized when it is declared.
Provide a no argument constructor with default values in case no initializes performing arithmetic with complex numbers are provided. Provide public methods for each of the following
a) Addition of two Complex numbers: The real parts are added together and the imaginary parts are added together.
b) Subtraction of two Complex numbers. The real part of the right operand is subtracted from the real part of the left operand and the imaginary part of the right operand is subtracted from the imaginary part of the left operand.
c) Print Complex numbers in the form (a, b) where a is the real part and b is the imaginary part.

Nah. I have other more pressing things to work on.

Perhaps you should give it a try yourself. When you have some code or specific questions about the parts you are stuck on, come back and post them and perhaps someone can offer some assistance.

commented: Reaching the goal is important...but not the path... -1

Fairly straight forward

``````class ComplexNumber{

private double real;
private double imaginary;

public ComplexNumber(double r, double i){
setReal(r);
setImaginary(i);
}

public ComplexNumber(){
setReal(0);
setImaginary(0);
}

public double getReal(){
return real;
}

public double getImaginary(){
return imaginary;
}

public void setReal(double r){
real = r;
}

public void setImaginary(double i){
imaginary = i;
}

real += c.getReal;
imaginary += c.getImaginary;
}

public void subtract(ComplexNumber c){
real -= c.getReal;
imaginary -= c.getReal;
}

public String toString(){
return "(" + real + ", " + imaginary + ")";
}

}``````
commented: We are not a homework service. Do NOT do their homework for them! -4

...........................................................

Copying and pasting is academic dishonesty and can get one expelled. By the way some people such as ME learn from examining others source and seeing how they approached the problem. I did not do this to spoon feed someone but rather to give them a road map as to how to approach this and similar problems.

Using your so called "Copying and Pasting"/"Spoon Feeding" method I self taught 5 computer languages.... So next time do not judge ones actions so critically.

I did not post this because i knew how to work it out. Am totally new in Java and need to know how to go about it. Thanks so much Arrorn, am studying your code

> I did not do this to spoon feed someone but rather to give them a road map as to how to approach this and similar problems.
Um... no. It is spoon feeding, plain and simple. You completed the entire assignment for him with absolutely no effort at all required on his part to figure out the solution.

You'll find that most here are pretty critical of that. Examples, code fragments, hints and explanations are all fine, but doing someone's homework for them isn't helping them and is harshly discouraged.

first of all how do you know it is his homework? do you happen to be able to read ones minds? In any of his posts did he EVER say it was his homework????????????????????????? Do you happen to know something I do not?????????

And as I said if he does copy and paste it is academic dishonesty and most universities/colleges expel one for that and most high schools or other schools punish one for it.
Also please Google "Complex Number java" and examine the first three results...... What do you see? Far more complete java source that handle complex numbers so please take into account what one could find online before one starts to berate one for giving someone an example.... Wait... thats almost EVERYTHING! so just don't.....

so just don't.....

That's what we are all saying.

first of all how do you know it is his homework?

Being deliberately obtuse won't win anyone over to your point of view.

Do you happen to know something I do not?????????

I know that adding 8 extra question marks doesn't really add any more weight to your question.

Also please Google "Complex Number java" and examine the first three results...... What do you see? Far more complete java source that handle complex numbers so please take into account what one could find online before one starts to berate one for giving someone an example.

That makes it even more egregious that he couldn't manage to even get started on his own. He just pasted the assignment on a forum with no code of his own to show, no intelligent questions, no indication of the merest hint of effort put into the assignment.

You weren't berated for giving him an example. You were berated for doing the assignment for him in its entirety. I think you can see the difference clearly.

first of all how do you know it is his homework?

If it wasn't homework and he was stuck without code, he would then go and learn/make a program that is simpler then the one he is currently trying to make. He would do this so that he could learn up to the level that he needs to complete this code.

Once he had some code, even if he was stuck only on the complex numbers part, but he had his other code (one that didn't involve complex numbers) then he wouldn't of needed to post his whole questions, and he could have just inquired about how to implement the complex numbers.

I know that adding 8 extra question marks doesn't really add any more weight to your question.

That is true. Extra punctuation doesn't help emphasize your question.

Also there are 9 questions marks.

> Also there are 9 questions marks.
Exactly. Eight of them are extras :P

Being deliberately obtuse won't win anyone over to your point of view.

Hmmmm... Is this statement somewhat ironic to anyone else?

I know that adding 8 extra question marks doesn't really add any more weight to your question.

Thank you for answering my rhetorical question as to whether you can read minds. It was to show my complete and utter confusion at you inferring that people cannot have innocent motives.

That makes it even more egregious that he couldn't manage to even get started on his own. He just pasted the assignment on a forum with no code of his own to show, no intelligent questions, no indication of the merest hint of effort put into the assignment.

First of all your entire argument is based off of the assumption that it is indeed an assignment. You obviously have trust issues or have not taken a debate class so I will teach you something. If an argument/opinion/plan is based off of an assumption and is found to be true it is viewed as lucky, luck is not assured and therefore is not looked well upon as being your sole patron as it is a fickle entity. If you happen to be wrong you happen to look completely stupid.
On the other side if you are lucky your opponent is looked at as being the "loser" by merest chance. If you are not lucky your opponent looks to has handed you your ass (pardon my "french") back to you on a silver platter. To summarize it is inadvisable to use an argument based off an assumption.

To actually analyze your reply, First of all he could only have pasted this assignment into the forums if it was an Online assignment and I doubt that due to the fact that it has several grammatical mistakes. Also, he did show some effort in the fact that he happened to have posted this statement/challenge/"assignment"(if that) on this forum in the first place.

Finally this assignment is so simple in its complexities anyone with an ounce of thought power and an understanding of Java could have written it, as proof I wrote it in under a minute (give or take 2-4, I didn't time myself). Due to this fact and as you put it shocking lack of use of google, I choose to take pity on him and "re-invent the wheel". As that this assignment is so simple an example and doing it for him is one and the same. I mean there were more complex problems on the AP Computer Science A Multiple Choice Section (Yes, the multiple choice section).

sirlink99: If everyone stopped doing something when they found that it was of greater scope than originally thought then we would not be sitting in front of our fancy/recently invented LCD/Plasma Computer Monitors.

Due to the fact that this argument/debate is entirely unrelated to the author's original post I will return to that.

If you wish me to walk you through my code to better explain it to you as I did not take the time to document it do not hesitate to ask. Also ericwalter if I happened to insult you by accident or intent in my debate with Ezzaral I formally apologize and wish to state that the statements were purely for argumental sake.

@Ezz.... dont start politics in a discussion forum ...

You could have just said your opinion to Arrorn but giving a link which explains all insignificant things is not a proper way to react....

commented: I posted no links. At least pay attention if you wish to make inane comments. -3

@Arrorn this discussion is going nowhere.
We do ask people to attempt to do their part of task instead of dropping on our forum expecting fast reply with full working solution, see this

@ericwalter if you want to continue discussion I do advice you to create new post and show some effort, even pseudo code/logical steps is more then nothing

@bbman do not join discussion if you have nothing constructive to say and just attempting to flame

@ALL