Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes CoOrd Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "CoOrd Class" Watch "CoOrd Class" New topic
Author

CoOrd Class

Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Please this is driving me mad, been trying for 5wks and still cant do it
After execution of line 2, what will the values for pt2.pointX and pt2.pointY be?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
After execution of line 2, what will the values for pt2.pointX and pt2.pointY be?
The best answer is found by adding a couple of System.out.prinln() method calls after line 2 in order to find out.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
If you can explain how it is not doing what you expect, we can help you better.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
The question is a past exam revision question, but i have no clue how to answer it. I bet this makes me look like a total idiot
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Tell us more specifically what you don't understand about this code.
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Well I understand that the class is building a point class which will abtain the axis for x and y within as graph or something.I also undestand that is contains 3 constructors, 2 attributes and and 2 objects which have been instantiated within it.BUt apart from this, I know no more about each of the lines.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
To answer this particular question, you don't need to know anything about the closest() method at all. Pretend it isn't there, or take it out of the code when you compile it.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
The code isn't going to compile as written because it contains a call to setPoints(), and there is no such method. There is a setPoint() method, and maybe that's what should have been called. Is this the source of your confusion?
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Im totally confused and totally lost now!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Rupinder Bains:
Im totally confused and totally lost now!

Do you know anything about what line 2 is doing?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Isnt line two setting the points out for x and y?
Anirban dutta
Ranch Hand

Joined: Aug 08, 2002
Posts: 89
dear runpinder,
Then where is the problem. You have yourself answered your question.
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
So will the value for x be 5 and the value for y be be 10?
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
How abouts for line 1 in main()? Will there be a value for pt1.pointX? will it be 2? or will it not maintain a value when it has been executed?
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
With line 3 will it automatically give the answer of wot the values within line 1 are? or will it set different values?from looking at it I believe that it will give the values of pt1 which is in line one, but I dint know what the values would be as an output in line1, or whether no values will output!!!Confusion confusion confusion!!! :roll:
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
If I was asked the question of what is type pt2? what would that mean? Could someone just explain the question in another way?Is the question asking me to explain what p2 is doing?if it is so, is it trying to set the points for the x and the y coordinates?or would I have to word this as it is setting NEWpoints for the x and y cxoordinates?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Rupinder Bains:
Isnt line two setting the points out for x and y?

Yes, I think you are on the right track! Can you explain how it is doing that?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Rupinder Bains:
How abouts for line 1 in main()? Will there be a value for pt1.pointX? will it be 2? or will it not maintain a value when it has been executed?

Line 1 is calling the constructor without any arguments, that is Coord(). What is this constructor doing?
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
The constructor is initializing the variables of Coord and having the argument passed on to it?(i think).
I dont know how line2 is setting the points but from looking at the coding, I thought it was due to the (5,10) which has obviously replaced x and y.
Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Does line 7 then print out pt3 coordinates which are the n closest to the number 5, or am I just totally out of line?
So lines 4 and 5 may be setting new points to x and y. So if lines 4 and 5 was executed x will be 20. and y will be 15. but would these two lines be changing the original numerals which were assigned to x and y,in line2 (5,10)?
Line 6 isnt a valid line of code is it? as the private method is not accessible. If the the main() method was inside the CoOrd class then line 6, may probably work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CoOrd Class
 
Similar Threads
finding closest point
Issue with wait/notify
pls suggest me a good style of programming
Need help writing a code involving bar charts!
cannot understand the exception in my code,please help