Here is some code I'm having trouble with. I'm trying to make an object oriented program that will run other programs using multidimensinal vectors. I know I have an error on my add, multiply, and invert methods because I'm not returning the right amount of information. I am somewhat new to using object oriented programming, and it's a tad bit confusing to me.
If someone could give me some pointers or help on how to do this, it would be appreciated. I am trying to figure this out, but I'm new to this type of programming, and it's still confusing in ways.
I've included one test that should run when the AnyDimensionalVector class is correct if that helps to see what kind of problems I'm experiencing.
It looks like your AnyDimensionalVector is supposed to hold a bunch of values that you can set and get by index. Right now I bet your ADV would pass this test:
I set the "0th" value to 1.0, got it back into f and checked that it was 1.0.
What you won't pass is this:
This will fail because your ADV only stores one value, not one value per index. So, first thing, write that first test and confirm it passes. Write the second test and confirm it doesn't. Then make the second one pass! Find a way to store multiple values indexed by 0, 1, etc. and make that test pass. Since you have a fixed size - given to ADV in the constructor - see if you can get away with array.
This should be fun! Making little tests and passing them is a neat way to code one feature at a time. Post some code if you get them going, ask if you need help getting the tests written.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Back up for a minute. Do you understand what a vector is in the mathematical sense? Do you know how to perform operations with them by hand? If not, you should learn that first. Once you can do these operations by hand, it shouldn't be too difficult to translate that into code.
I worked on it a bit, and not everything is finished. My main problems that I am trying to work out is that I'm getting an error with my lines that say "new AnyDimensionalVector". I have been looking at it with my friend and neither of us can determine why I'm getting an error with "new".
AnyDimensionalVector.java:21: cannot resolve symbol symbol : variable newVector location: class AnyDimensionalVector return new AnyDimensionalVector(newVector);