Results 1 to 16 of 16
- 02-27-2011, 01:11 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
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:
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: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; }
However that gives me this error: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; }
P.java:107: cannot find symbol
symbol : method decreaseBy(double)
location: class MP
velMultByTimeWDrag = velocityMultByTime.decreaseBy(dragCoeff);
^
1 error
- 02-27-2011, 02:17 PM #2
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:
- 02-27-2011, 02:33 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
I've defined this operation in a PV class with this code:
So this would subtract the vector dragCoeff from the vector velocityMultByTime right.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; }
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.
- 02-27-2011, 02:52 PM #4
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 02:56 PM.
Sorry, I only speak machine language. Yes or a No?:confused:
- 02-27-2011, 03:02 PM #5
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:
- 02-27-2011, 03:11 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
- 02-27-2011, 03:14 PM #7
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
I've changed the code slightly in P:
So I've now defined velocityMultByTime from MP rather than in P (I thought this was the better way).Java Code:public void updateProperties(GravitationalField gravField, MassiveParticle particle, MassiveParticle velocityMultByTime, String request)
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.
- 02-27-2011, 03:29 PM #8
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
- 02-27-2011, 03:36 PM #9
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:
- 02-27-2011, 03:51 PM #10
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
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:
Which would work it seems apart from issues: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; }
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:
-
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).
- 02-27-2011, 04:11 PM #12
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
Like this?
don't think that's quite right though (since it doesn't work) I get these errors: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; ...
[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 errorsLast edited by javak; 02-27-2011 at 04:18 PM.
-
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 BasicsLast edited by Fubarable; 02-27-2011 at 04:31 PM.
- 02-27-2011, 04:33 PM #14
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
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).
-
What dot product code? Remember we only know about your project what you tell us.
I'm sorry, I'm confused, what's the question here (or is there a question)?I don't see what else I'll need to do to just multiply the components of the vectors (in this case vector1=vector2).
- 02-27-2011, 04:43 PM #16
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
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
-
problem with a method of a extended class JpcapWriter.
By swarna_vw in forum NetworkingReplies: 0Last Post: 04-15-2010, 12:00 PM -
Returned type changes if class is extended. How?
By Gelembjuk in forum New To JavaReplies: 10Last Post: 10-31-2008, 11:18 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 08:30 AM -
cannot find symbol class error
By po0oker in forum New To JavaReplies: 5Last Post: 10-31-2007, 02:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks