Printing X,Y coordinates in java

Thread Starter

k_bhushan27

Joined Jan 26, 2012
11
hi im confused about this question i have where i am supposed to write one line of code for a rectangles x and y coordinates in the form of (x,y)

here is the question:
Write a CoordinateTester program that constructs a Rectangle object
and then prints its coordinates in the format (x, y). You must use
the getX and getY methods. Also print the expected answer.

public class CoordinateTester
{
public static void main(String[] args)
{
Rectangle box = new Rectangle(10, 20, 30, 40) ;

if anyone could please help me out it will be greatly appreciated!
 

kubeek

Joined Sep 20, 2005
5,794
could be anything, look into the Rectangle class and see what methods you have available.
Then print it something like println("X: "+box.getSomething()+"Y: "+box.getSomethingElse());
 

kubeek

Joined Sep 20, 2005
5,794
And the question is?
Use printf for the floating point format. Also you could ask your professor which of those four coordinates from new Rectangle(10, 20, 30, 40) are you supposed to print.
And let me say it AGAIN, without the Rectangle class I have to guess what is what and what is being asked from you.
 

Thread Starter

k_bhushan27

Joined Jan 26, 2012
11
the question is in my first post! and my prof stated that the in the new Rectangle(10,20,30,40) x = 10, y = 20, width = 30, height = 40
 

kubeek

Joined Sep 20, 2005
5,794
Ok, then you should have enought information to write the line he asks. Try writing it down and we´ll see how it goes.
 

Thread Starter

k_bhushan27

Joined Jan 26, 2012
11
thats the problem, i have the information i just cant obtain the right line of code in order to recieve the output of (10.0,20.0)
 

Thread Starter

k_bhushan27

Joined Jan 26, 2012
11
System.out.println("X: "+box.getX()+"Y: "+box.getY());

i used your format but still havent recieved the same output.
i got: X: 10.0 Y: 20.0
 

kubeek

Joined Sep 20, 2005
5,794
So maybe you should rewrite it so that it outputs what you need? Like System.out.println("Expected: ......
Try changing the code you posted before and see what the changes do with the printed text. Or try reading some tutorial.

You wouldn´t learn anything if I just simply told you the answer, so try figuring it out on your own.
 

Thread Starter

k_bhushan27

Joined Jan 26, 2012
11
thats very true i wouldnt learn anything if you told me the answer. i was hoping if you could explain how you derive the answer itself! ive changed the code to make it (x,y) but i still dont get the correct output. i dont know what im doing wrong
 

Thread Starter

k_bhushan27

Joined Jan 26, 2012
11
ive looked at tutorials but i cant find anything that relates to my question, right now what i sent u before is what im working with right now -_-
 

kubeek

Joined Sep 20, 2005
5,794
So how are you supposed to print the word expected if you cant use it? Does your professor even know what he actually wants from you?
 
Top