Results 1 to 4 of 4
  1. #1
    jester-race is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Invocation of a Square

    Hello everybody.

    I'm a few weeks into my first Java course and the online exercises are proving troublesome. My teacher was frustrated when she was unable to come up with the correct answers or find any kind of teacher's file containing the answers of a few questions. I'm using the Pearson MyProgrammingLab, and it's incredibly picky about what it considers to be "correct". Also, I find that the instructions are often unclear

    That said, I have just one question for now that I have not yet been able to ask about. It's perfectly possible that I'm just not getting something this time, rather than it being the website's fault, so to speak. Here it is:

    Write the invocation (method name with arguments) needed to display the outline of a square whose sides are 60 pixels and whose top right corner is located at (100,200).

    Okay, so it is not asking me to write a statement. No semi-colon should be necessary. Also, no Graphics object need be created/used either. It's just asking for the method, the coordinates, and the size. This is my answer:

    drawRect(100,200,60,60)

    I have also tried: void drawRect(100,200,60,60), void drawRect(100,200,60,60); and drawRect(100,200,60,60);

    It's such a simple task, but clearly I am doing something wrong. What do you think?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Invocation of a Square

    I assume (like you, I guess) that we are talking about java.awt.Graphics here. That's an assumption worth checking: make sure they haven't slipped in a reference to some other graphics drawing class and are talking about that one.

    I would try random (but legal) spaces between the argument values. Because that's the sort of thing computers get wrong.

    I would try fillRect(). Because that's the sort of thing human problem posers get wrong.

    I would have a read of the API docs. "Draws the outline of the specified rectangle. The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height. The rectangle is drawn using the graphics context's current color." You might think (*) that if the left edge is at x and the right edge is at x+width that means that the rectangle is width+1 pixels across. So I would try drawRect(100,200,59,59).

    (*) But see the note at the top of the Graphics docs about the infinitely thin paths and drawing outlines. 60 is the width, but I'd try 59 anyway.

    Finally (in reality, firstly), I'd try Google. Chances are you're not the first to hit this. Search for something in the problem text that looks fairly unique to the question and put it in quotes for an exact match.

  3. #3
    jester-race is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Invocation of a Square

    All of your suggestions make perfect sense to me, but MyProgrammingLab disagrees. I'll just have to skip it and ask the prof next week. These exercises are not for marks anyways. I just do them for practice.

    I appreciate your thoughtful response though. I make a point of carefully reading the appropriate chapter(s) of my text and (if necessary) using Google before asking people for help.

    Oh, and it is java.awt.Graphics that I'm talking about. :)

    EDIT:

    Oooh boy. This one is definitely my bad... the first question anyway. For some reason, I thought that they were instructing me to draw a rectangle with the top left point at (100,200). No, it actually gives the location of the top right corner. If the top right corner is at (100,200) then the location of the top left corner would be at 100 - width, where width = 60. The correct answer is this:

    drawRect(40,200,60,60)

    Just figured I'd share that in case anybody else has a problem like this. When drawing a shape, pay attention to which corner you get the coordinates to!
    Last edited by jester-race; 02-04-2012 at 09:16 AM.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Invocation of a Square

    Great. I'm glad you've got that sorted out.

    You did post top RH corner. So you, me (and everybody who didn't respond, but they will protest otherwise) are all in the same boat: didn't read the question and rushed ahead assuming it was posed in a sane fashion...

Similar Threads

  1. RMI (remote method invocation) Java
    By Stijn_vdd in forum Networking
    Replies: 1
    Last Post: 03-03-2011, 06:14 PM
  2. Listening to JPopupMenu invocation
    By nik_meback in forum AWT / Swing
    Replies: 5
    Last Post: 12-03-2010, 03:06 PM
  3. RMI Invocation
    By kavithakr in forum Advanced Java
    Replies: 1
    Last Post: 03-14-2009, 10:04 PM
  4. Invocation error in JMock
    By tanvij in forum New To Java
    Replies: 0
    Last Post: 05-14-2008, 10:05 AM
  5. HELP: Method Invocation
    By rjuyal in forum Advanced Java
    Replies: 4
    Last Post: 04-07-2008, 12:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •