I am a newbie to Java, just been fiddling with the code for a while.
public class ThreeVector {
private double x,y,z; // definign local variables
public ThreeVector(){} // a constructor that has no input
public ThreeVector (double va1,double va2, double va3){va1=x;va2=y;va3=z;};// creatign a constructor , so can be used for calling by a method later
// Takes 3 values
public double magnitude (){
double y1= Math.sqrt(x*x+y*y+z*z);
return y1 ; // finds the magnitude of a vector
}
public ThreeVector unitv(){
ThreeVector unitv= new ThreeVector ();
unitv.ThreeVector(x/magnitude(),y/magnitude(),z/magnitude());
}
Now here is where I get stuck. I created an object unitV so I could call the ThreeVector constructor, but the compiler keeps saying to create a new method for ThreeVector.
Not sure whats going on...
ThreeVector?public ThreeVector unitv()...but does not return an instance of a ThreeVector. I think you want to remove the unitv method and do something like Luiggi suggests.