-6

I am very new to java and I have this assignment which I have been working on very intensivly for the last 14 days.

The assignement is to build a class vector with max. 7 dimensions: what I came with to make the vector multi-dimensional is that I declared 7 variables

private double x, y,z,i,j,k,f;

which then I will initialize in constructors etc.. Well, my first question: did I build a 7 dimensional vector in this way?

OR,

should I somehow work with arrays for this problem like declaring an array;

double [][] = data; // which generates a 2D-Vector.

AND,

double [][][][][][][] = data1; //which declare a 7D-Vector??!!!

for any helpful information I will be very thankful

thanks all and Best regards to you :)

azurefrog
  • 10,785
  • 7
  • 42
  • 56
Rick_C132
  • 1
  • 2
  • Check the answer on this question: [HERE](https://stackoverflow.com/a/7913679/4250184) – Bobzone Nov 14 '17 at 21:54
  • 2
    Define "vector" - do you mean it in the sense of a mathematical ordered tuple like (1,2,3)? Or in the sense of eg. c++ and Java `Vector` class which stores a list of values? – hnefatl Nov 14 '17 at 21:55
  • 1. No. 2. Maybe ... depending on what `data` is. – Stephen C Nov 14 '17 at 22:39

2 Answers2

1

did I build a 7 dimensional vector in this way?

Yes you have. A vector is a way of storing a magnitude and direction, which is done by correctly assigning the value and sign of each double. A vector in 2-space would require two values, and a vector in 7-space would require 7 values, which you have.

should I somehow work with arrays for this problem like declaring an array;

You can, but you don't need a multi-dimensional array. To store a single vector in a 7-space, you just need an array of length 7:

double[] data = new double[7]; // store a 7D vector

You could then modify your existing code, replacing x with data[0], y with data[1] and so on.

azurefrog
  • 10,785
  • 7
  • 42
  • 56
0

You don't need a multidimensional array for a vector. By definition, a vector has only a single column; if it had multiple columns, it would be a matrix, not a vector.

If you want a vector of size n, just create a single-dimensional array of size n. You could use an ArrayList or something like that, but there's less of a point because you (presumably) know the size of the vector in advance. (If that's not the case, ArrayList could be good).

The most interesting part of a Vector class is actually the operations, so use whatever data structure allows you to retain order and conveniently perform your operations. Truthfully, that'll probably be an array of size n.