## liquifiedkronic 3 years ago (Java) Specify, design, and implement a class that can be used to keep track of the position of a location in three-dimensional space.

1. opiesche

Let's start with a few hints: for 3-dimensional space, how many coordinates would you need to describe the position of a point? Each of those would take the form of a scalar. For such a class, you'll likely want to be able to read and write the respective coordinates - update them when the position of the point changes, read them to find out where it is...

2. liquifiedkronic

You would need 3 coordinates, xyz.

3. opiesche

Exactly! So, those would be data members of your class. Then you'll need methods to access and modify them.

4. ecdown

This would be a basic class to specify a point. Though it might be useful to make the members public and not use the getter setter methods. class threedcoord { private int x = 0; private int y = 0; private int z = 0; int getx() { return x; } int gety() { return y; } int getz() { return z; } void setx(int inp) { x = inp; } void sety(int inp) { y = inp; } void setz(int inp) { z = inp; } }

5. opiesche

while it might seem useful, and may be ok for a small class like this, you should be extremely careful with making data members public. if you ever need to add functionality like logging everytime the position is changed, you would have to change the class and *every instance in your code where you access one of the public members*. once you've written a couple of thousand lines of code using your class in various places, this can become difficult. public data members should only be used in very specific circumstances - some say, data members should never be public.

6. liquifiedkronic

Oh I see now. Thanks for the responses!

7. llib_xoc

I absolutely agree with opiesche. What if you write the Point class, refer to the coordinates in lots of places, the decide that the coords need to be *float* numbers? You'll have to change all the references! A great mantra for programming is to organize your code so that you rarely need to change anything in more than one place.