Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Java] Objects
#1
So our teacher did a pretty bad job of explaining what objects are, so basically I have no idea how to use them, their format, what to input, etc. etc.

Our assignment is to basically create a point from (1,1) to (20,20), have the user guess a point, and see how far/close it is. Using objects.

His "Point" class is

 Spoiler

Assume that the "//look on webpage" pretty much shows nothing useful. I'm supposed to put something there.

Steps he told us to do to complete the objective:

1. Copy paste the above file into jcreator (the program we use to code).
2. Insert some stuff in the //look on webpage part (aka fix the Constructor Summary).
3. Decompile.
4. Create another file and code and decompile and stuff to complete the objective.

So...how do I do this? Like I said, I have literally no idea to do this. What is the point of all of those summaries? What does void move mean? And to use it do I use point(dot)...what?

I'm going to read the textbook later when I get home in an attempt to grasp some understanding, but I have some downtime at the moment and I thought "Hey, this is a great moment to ask Southperry!"
Reply
#2
I am assuming that you mean "compile" when you say "decompile". I am guessing that those summaries are just supposed to be descriptions of what the method does. You didn't ask about "public boolean equals" or "public String toString()" so I'm assuming that you're comfortable with the concept of functions that return a value. "void move" is just a function that doesn't return any value.

Is it supposed to be "public void move" or is it supposed to not have an access specifier?

You would call move like so:

Point point = new Point(5, 5); // Create the Point object
point.move(10, 15); // move it
Reply
#3
I am assuming that you mean "compile" when you say "decompile". I am guessing that those summaries are just supposed to be descriptions of what the method does. You didn't ask about "public boolean equals" or "public String toString()" so I'm assuming that you're comfortable with the concept of functions that return a value. "void move" is just a function that doesn't return any value.

Is it supposed to be "public void move" or is it supposed to not have an access specifier?

You would call move like so:

Point point = new Point(5, 5); // Create the Point object
point.move(10, 15); // move it
Reply
#4
I've had at least 3 sources telling me stuff about Objects (the Sun tutorial, my cousin and my instructor), but the idea never really clicked until I figured it out for and by myself, so I'm not sure how much help I'll be, but I'll relay my understanding of OOP here.

 subject to conceptual derp
Reply
#5
Spaz Wrote:I am assuming that you mean "compile" when you say "decompile". I am guessing that those summaries are just supposed to be descriptions of what the method does. You didn't ask about "public boolean equals" or "public String toString()" so I'm assuming that you're comfortable with the concept of functions that return a value. "void move" is just a function that doesn't return any value.

Is it supposed to be "public void move" or is it supposed to not have an access specifier?

You would call move like so:

Point point = new Point(5, 5); // Create the Point object
point.move(10, 15); // move it

1) Oops, meant compile.
2) I have no idea what those are, either D=.
3) It's supposed to not have an access specifier, I guess. I have no idea, really. I just copy pasted.

So say I have variable pointA. To use this class, would I do something like, pointA.equals(....I'm guessing Point goes here)? And pointA.toString(...I'm also guessing Point goes here?)

Kalovale Wrote:I've had at least 3 sources telling me stuff about Objects (the Sun tutorial, my cousin and my instructor), but the idea never really clicked until I figured it out for and by myself, so I'm not sure how much help I'll be, but I'll relay my understanding of OOP here.

 subject to conceptual derp

Well, thanks, that makes a lot more sense than what my teacher tried to teach us X_X. Now I just need to figure out how to use this class Point. Starting to read the textbook, finally.
Reply
#6
Corn Wrote:So say I have variable pointA. To use this class, would I do something like, pointA.equals(....I'm guessing Point goes here)? And pointA.toString(...I'm also guessing Point goes here?)

Point pointA = new Point(5, 6);
Point pointB = new Point(5, 6);
Point pointC = new Point(15, 1);

boolean shouldBeTrue = pointA.Equals(pointB);
String pointString = pointB.toString();
System.out.println(pointString);
System.out.println(pointC.toString());
Reply
#7
Reply
#8
I finally get it now guys, thanks >_>.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)