Printing X,Y coordinates in java

Discussion in 'Programmer's Corner' started by k_bhushan27, Jan 26, 2012.

  1. k_bhushan27

    Thread Starter New Member

    Jan 26, 2012
    11
    0
    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!
     
  2. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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());
     
  3. k_bhushan27

    Thread Starter New Member

    Jan 26, 2012
    11
    0
    hey! this is what my prof put as the what needs to be the output.

    System.out.println("Expected: (10.0, 20.0)") ;
     
  4. k_bhushan27

    Thread Starter New Member

    Jan 26, 2012
    11
    0
    System.out.println("Expected: (10.0, 20.0)") ;
     
  5. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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.
     
  6. k_bhushan27

    Thread Starter New Member

    Jan 26, 2012
    11
    0
    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
     
  7. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Ok, then you should have enought information to write the line he asks. Try writing it down and we´ll see how it goes.
     
  8. k_bhushan27

    Thread Starter New Member

    Jan 26, 2012
    11
    0
    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)
     
  9. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    so post what you have so far
     
  10. k_bhushan27

    Thread Starter New Member

    Jan 26, 2012
    11
    0
    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
     
  11. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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.
     
  12. k_bhushan27

    Thread Starter New Member

    Jan 26, 2012
    11
    0
    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
     
  13. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    I cant tell you what you did wrong if you dont post what you did :D
     
  14. k_bhushan27

    Thread Starter New Member

    Jan 26, 2012
    11
    0
    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 -_-
     
  15. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Post the entire line you have and I will show you what you need to change.
     
  16. k_bhushan27

    Thread Starter New Member

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

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    So what is the problem making it System.out.println("Expected: ("+box.getX() + ", " + box.getY() + ")" );
     
  18. k_bhushan27

    Thread Starter New Member

    Jan 26, 2012
    11
    0
    i asked my professor the same question but he said i cant use "Expected" -___-
     
  19. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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?
     
  20. codehead

    Member

    Nov 28, 2011
    56
    11
    Yet earlier in the thread, you said:

    Maybe you need to restate what you're asking here—kubeek has been answering you very clearly.
     
Loading...