Let's start at the beinning.
let me repost your code in code tags so it's easier to follow :
I see you provide a Consturctor for you class ThreeVector
This constructor tells it to create a ThreeVector based on 3 integer parameters. First problem i spot here, is that no matter what you pass through to the constructor, nothing happens with it.
To solve this, i propose you make 3 instance variables (i, j and k) and mark them private. Instance are directly under the class declaration, meaning not in any method.
Then in your constructor you need to assign the values passed to the instance variables of the current object:
Now we have an object that actualy contains the values that we passed to it.
With the method at line 8 (magnitude(int xx, int yy, int zz)) i assume you want to calculate the magnitude of the current ThreeVector
If that is the case you don't need to pass it any parameters, you can use the instance variables i, j and k and you can change line 8 to :
At line 16 you write out your object. What actualy gets Written out is what is returned from the ThreeVector's toString() method. Which, because it is not defined is the one inherited from it's superclass, Object
(every class inherits from Object).
If you want something meaningfull when you print the object, then simply override the toString() method to have it return something usefull. Something like :
At line 17 i think you want to calculate the magnitude of the ThreeVector
. This can be done by calling the method magnitude on the ThreeVector
and, if you want to do something with the value, assign it to a variable:
I hope this was clear enough.
If it wasn't, post your new version of your code with the additional question.