Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with Objects..

 
MP Olsen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



Here is the class I'm trying to run with it.

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Layne
 
MP Olsen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);



[ April 03, 2005: Message edited by: MP Olsen ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic