• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CoOrd Class

 
Rupinder Bains
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can explain how it is not doing what you expect, we can help you better.
 
Rupinder Bains
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell us more specifically what you don't understand about this code.
 
Rupinder Bains
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im totally confused and totally lost now!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rupinder Bains:
Im totally confused and totally lost now!

Do you know anything about what line 2 is doing?
 
Rupinder Bains
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isnt line two setting the points out for x and y?
 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear runpinder,
Then where is the problem. You have yourself answered your question.
 
Rupinder Bains
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So will the value for x be 5 and the value for y be be 10?
 
Rupinder Bains
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic