Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

liquifiedkronic Group Title

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

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. opiesche Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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 years ago
  2. liquifiedkronic Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    You would need 3 coordinates, xyz.

    • 2 years ago
  3. opiesche Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  4. ecdown Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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; } }

    • 2 years ago
  5. opiesche Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
  6. liquifiedkronic Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh I see now. Thanks for the responses!

    • 2 years ago
  7. llib_xoc Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.