Results 1 to 16 of 16
  1. #1
    javak is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default Extended Class - Cannot Find Symbol

    The class MP models projectile motion. Using the defined gravField in the GV class and also a defined time interval, the acceleration is calculated, then from this the velocity and position of the particle at different time intervals. Hopefully that makes sense :) . The program works fine, but now I need to add the class P which inherits from MP and is used to add the property of drag/air resistance to the particle motion.

    This is the current code in MP:

    Java Code:
    public void updateProperties(GF gravField, MP particle, String request)
    	{
    		PV accelMultByTime = new PV(3);
    		accelMultByTime = gravField.accelDueToGravity(particle, request);
    		accelMultByTime.scaleBy(deltaTime);		
    		velocityVector.increaseBy(accelMultByTime);
    		
    		PV velocityMultByTime = new PV(3);
    		
    		velocityMultByTime = velocityVector.scaleByReturnVector(deltaTime);
    
                    positionVector.increaseBy(velocityMultByTime);
    		
    		return;
              }
    What I thought is that I could just slightly adjust this, so that the acceleration in MP is send to P, where the drag is defined and subtracted from the acceleration, producing a new set of velocity/position values. Again I hope that makes sense :) .

    Java Code:
    // method to factor in drag
    
    public class P extends MP
    {
    	// private class variables
    	
    	private double dragCoeff;
    
            // public class variables
    	
    	public MP velocityMultByTime;
    	
    	public void updateProperties(MP particle, String request)
    	{		
    		
    		PV velMultByTimeWDrag = new PV(3);
    		velMultByTimeWDrag = velocityMultByTime.decreaseBy(dragCoeff);
    		positionVector.increaseBy(velMultByTimeWDrag);
    		
    		return;	
    	}
    However that gives me this error:

    P.java:107: cannot find symbol
    symbol : method decreaseBy(double)
    location: class MP
    velMultByTimeWDrag = velocityMultByTime.decreaseBy(dragCoeff);
    ^
    1 error

  2. #2
    BiteMuncher's Avatar
    BiteMuncher is offline Member
    Join Date
    Feb 2011
    Location
    South Africa
    Posts
    51
    Rep Power
    0

    Default

    Are you sure the method decreaseBy() exists in MP?
    If so is decreaseBy() declared public.
    If decreaseBy() is abstract it needs to be implemented in P.
    Sorry, I only speak machine language. Yes or a No?:confused:

  3. #3
    javak is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    I've defined this operation in a PV class with this code:

    Java Code:
    	/** 
    	* Method to subtract PV "z" from this object
    	* 
    	* PV is decreased by z=[c,d] so that the new
    	* vector is given by ([a-c, b-d]).
    	*/
    	public void decreaseBy(PV z)
    	{
    		for(int i=0; i<component.length; i++)
    			
    			component[i] -= z.component[i];
    		return;
    	}
    So this would subtract the vector dragCoeff from the vector velocityMultByTime right.

    How would I refer to this bit of code in PV in P? I could just write it again in P but I know I should be able to reference it somehow.

  4. #4
    BiteMuncher's Avatar
    BiteMuncher is offline Member
    Join Date
    Feb 2011
    Location
    South Africa
    Posts
    51
    Rep Power
    0

    Default

    velocityMultByTime is an instance of MP. Therefore only methods defined in MP can used by this object.
    If you want PV to execute this method, you can declare decreaseBy() as an abstract method in MP i.e. 'public abstract 'dataType' decreaseBy();'
    MP needs to be declared abstract for this to work. (public abstract class MP).
    No implementation of the the decreaseBy() method is done in MP so just code a single line as in my example.
    Thenin PV you implement the code:
    public 'returnType' decreasBY("")
    {
    //code
    }

    I also noticed you do not have a return type on decreaseBy() so the line:
    'velMultByTimeWDrag = velocityMultByTime.decreaseBy(dragCoeff);' returns void which is a problem. Rectify that.

    Of course 'public MP velocityMultByTime;' would have to be changed to:
    PV velocityMultiplyByTime = new PV();
    Construct a simple constructor method in PV.
    public PV(){};

    Try it and let me know.
    Last edited by BiteMuncher; 02-27-2011 at 03:56 PM.
    Sorry, I only speak machine language. Yes or a No?:confused:

  5. #5
    BiteMuncher's Avatar
    BiteMuncher is offline Member
    Join Date
    Feb 2011
    Location
    South Africa
    Posts
    51
    Rep Power
    0

    Default

    One more thing.
    If there are other classes besides PV that may use the decreaseBy() method I suggest you go with the above.
    If on the other hand class PV is the only child class using 'decreaseBy()', don't bother making MP abstract or declare an abstract decreaseBy() method in MP, just code a regular public method in PV.
    Sorry, I only speak machine language. Yes or a No?:confused:

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by javak View Post
    I've defined this operation in a PV class with this code:

    Java Code:
    	public void decreaseBy(PV z)
    	{
    	[ ... ]
    	}
    That method takes a PV object as a parameter; in you original post you're trying to pass a double value; that was what your compiler was complaining about.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    javak is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    I've changed the code slightly in P:

    Java Code:
    	public void updateProperties(GravitationalField gravField, MassiveParticle particle, MassiveParticle velocityMultByTime, String request)
    So I've now defined velocityMultByTime from MP rather than in P (I thought this was the better way).

    I don't really understand all of those things you're said, I think it would be easier to just define a decreaseBy method in the P class.

    So the code would be pretty much the same as I have now in PV right? The vector velocityMultByTime is already defined from MP and then just need to define the vector dragCoeff to be subtracted? I'm not sure how to do that, since dragCoeff is proportional to a value DragConst times the particle velocity presumably that's velocityMultByTime at this point.

  8. #8
    javak is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by javak View Post
    I've changed the code slightly in P:

    Java Code:
    	public void updateProperties(GravitationalField gravField, MassiveParticle particle, MassiveParticle velocityMultByTime, String request)
    So I've now defined velocityMultByTime from MP rather than in P (I thought this was the better way).

    I don't really understand all of those things you're said, I think it would be easier to just define a decreaseBy method in the P class.

    So the code would be pretty much the same as I have now in PV right? The vector velocityMultByTime is already defined from MP and then just need to define the vector dragCoeff to be subtracted? I'm not sure how to do that, since dragCoeff is proportional to a value DragConst times the particle velocity presumably that's velocityMultByTime at this point.
    I've just seen the replies that were after the 1:52 post this was in response to.

    I think I can just code a bit of simple maths in P to sort it.. maybe. I'll have a go.

  9. #9
    BiteMuncher's Avatar
    BiteMuncher is offline Member
    Join Date
    Feb 2011
    Location
    South Africa
    Posts
    51
    Rep Power
    0

    Default

    Quote Originally Posted by javak View Post
    I've changed the code slightly in P:

    Java Code:
    	public void updateProperties(GravitationalField gravField, MassiveParticle particle, MassiveParticle velocityMultByTime, String request)
    So I've now defined velocityMultByTime from MP rather than in P (I thought this was the better way).

    I don't really understand all of those things you're said, I think it would be easier to just define a decreaseBy method in the P class.

    So the code would be pretty much the same as I have now in PV right? The vector velocityMultByTime is already defined from MP and then just need to define the vector dragCoeff to be subtracted? I'm not sure how to do that, since dragCoeff is proportional to a value DragConst times the particle velocity presumably that's velocityMultByTime at this point.
    Understand that P extends MP in other words P is a child class of MP.
    If P defines the decreaseBy() method it meens decreasedBy() is a unique method to P.
    P inherits from MP but has declared its own method decreasedBy().
    velocityMultByTime is an object created from MP so this object cannot use the decreasedBy() method. If you want an MP object to execute decreaseBy() you would have to implement this method in MP.
    Also you declared 'private double dragCoeff', but
    public void decreaseBy(PV z) accepts a PV object.
    Try public void decreaseBy(Double z)
    Sorry, I only speak machine language. Yes or a No?:confused:

  10. #10
    javak is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    Thanks for that.

    I've just been trying a different method that seems simpler. This is the bit of code I now have in P:

    Java Code:
            // method to factor in drag
    	
    	public void updateProperties(GravitationalField gravField, MassiveParticle particle, MassiveParticle velocityVector, String request)
    	{		
    	
    	PhysicsVector velSqrd = new PhysicsVector(3);
    	
    	velSqrd = velocityVector*velocityVector;
    	
    	PhysicsVector velDrag = new PhysicsVector(3);
    	
    	velDrag = dragCoeff*velSqrd;
    	
    	PhysicsVector velocityMultByTime = new PhysicsVector(3);
    		
    	velocityMultByTime = velDrag.scaleByReturnVector(deltaTime);
    
    	positionVector.increaseBy(velocityMultByTime);
    		
    	return;	
    	}
    Which would work it seems apart from issues:

    Projectile.java:108: operator * cannot be applied to MassiveParticle,MassiveParticle
    velSqrd = velocityVector*velocityVector;
    ^
    Projectile.java:112: operator * cannot be applied to double,PhysicsVector
    velDrag = dragCoeff*velSqrd;
    ^
    2 errors

    Why can't I multiply? :confused:

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    What is velocityVector? It's a MassiveParticle variable. What does it mean to multiply one MassiveParticle variable to another? It doesn't have meaning, and that's what the compiler is complaining about as it would be just like trying to multiply two Strings -- myString1 * myString1. There's a similar issue with the other error, and again the error message returned is pretty self explanatory. Perhaps you need to give MassiveParticle a method that returns the square of its velocity vector (likely the dot product).

  12. #12
    javak is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    Like this?

    Java Code:
    public double dotProduct(MassiveParticle velocityVector, MassiveParticle velocityVector)
    	{
    		double dotProduct = 0;
    		
    		for(int i=0; i<vecA.getLength(); i++)
    		{
    			dotProduct += MassiveParticle velocityVector.component[i] * MassiveParticle velocityVector.component[i];
    		}
    		
    		return dotProduct;
    	}
    	
    public void updateProperties(GravitationalField gravField, MassiveParticle particle, MassiveParticle velocityVector, String request)
    	{	
    		
    	PhysicsVector velSqrd = new PhysicsVector(3);
    	
    	velSqrd = dotProduct;
    
    ...
    don't think that's quite right though (since it doesn't work) I get these errors:

    [I]
    Projectile.java:115: ';' expected
    dotProduct = MassiveParticle velocityVector.component[i] * MassiveParticle v
    elocityVector.component[i];
    ^
    Projectile.java:115: not a statement
    dotProduct = MassiveParticle velocityVector.component[i] * MassiveParticle v
    elocityVector.component[i];
    ^
    Projectile.java:115: ';' expected
    dotProduct = MassiveParticle velocityVector.component[i] * MassiveParticle v
    elocityVector.component[i];
    ^
    Projectile.java:115: not a statement
    dotProduct = MassiveParticle velocityVector.component[i] * MassiveParticle v
    elocityVector.component;

    ^
    4 errors
    Last edited by javak; 02-27-2011 at 05:18 PM.

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by javak View Post
    don't think that's quite right though (since it doesn't work)
    No, that makes even less sense. Avoid trying to make up code or guessing as that never works. You are trying to do multiplication on two objects with the multiplication operator and this cannot be done but rather can only be done on numbers. If you can't or are not allowed to write a method inside of MassiveParticle to do this, then you'll need to extract the actual numbers from the velocity vector that a MassiveParticle holds and use these numbers to do your multiplication. For example if your particles are represented in 3-space it may be possible to get the x, y, and z components of both particle's velocity and then use them to multiply them together, x1*x2 + y1*y2 + z1*z2, etc.. But regardless, multiplication can only be done on numbers.

    You may wish to review the basic tutorials on this: Language Basics
    Last edited by Fubarable; 02-27-2011 at 05:31 PM.

  14. #14
    javak is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    you need to give MassiveParticle a method that returns the square of its velocity vector (likely the dot product).
    That dot product code multiplies vector1 by vector2 fine.. so I don't get why it doesn't work for what is effectively vector1=vector2. I thought that it just takes the components of each vector and multiplies them together i.e. if have vector1 = [2,3] and vector2 = [4,5] then get the returned variable dotProduct = [8,15].

    I don't see what else I'll need to do to just multiply the components of the vectors (in this case vector1=vector2).

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by javak View Post
    That dot product code multiplies vector1 by vector2 fine.. so I don't get why it doesn't work for what is effectively vector1=vector2. I thought that it just takes the components of each vector and multiplies them together i.e. if have vector1 = [2,3] and vector2 = [4,5] then get the returned variable dotProduct = [8,15].

    What dot product code? Remember we only know about your project what you tell us.



    I don't see what else I'll need to do to just multiply the components of the vectors (in this case vector1=vector2).
    I'm sorry, I'm confused, what's the question here (or is there a question)?

  16. #16
    javak is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    What dot product code?
    Previously created a class PV which had methods in it to calculate things such as dot product, scalar multiplication of vector, etc. It included this method:

    /** This method calculates the dot product using the formula [a,b].[c,d] = ac+bd
    * As is necessary for vectors.
    *
    * @param vecA The first vector to be multiplied.
    * @param vecB The second vector to be multiplied.
    *
    * @return dotProduct The value of the dot product of vecA and vecB.
    */

    public double dotProduct(PV vecA, PV vecB)
    {
    double dotProduct = 0;

    for(int i=0; i<vecA.getLength(); i++)
    {
    dotProduct += vecA.component[i] * vecB.component[i];
    }

    return dotProduct;
    }

    So since my program currently just finds the velocity, and I need to find the velocity-squared, I thought I could just adapt this code. But it doesn't seem to work that way then.

Similar Threads

  1. Replies: 0
    Last Post: 04-15-2010, 01:00 PM
  2. Returned type changes if class is extended. How?
    By Gelembjuk in forum New To Java
    Replies: 10
    Last Post: 10-31-2008, 12:18 PM
  3. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  4. Replies: 3
    Last Post: 05-01-2008, 09:30 AM
  5. cannot find symbol class error
    By po0oker in forum New To Java
    Replies: 5
    Last Post: 10-31-2007, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •