Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with Checkerboard GraphicsProgram (Due Tomorrow!)

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with Checkerboard GraphicsProgram (Due Tomorrow!)

    import acm.graphics.*;
    import acm.program.*;
    import java.awt.*;

    public class Checkers extends GraphicsProgram {

    public void run() {
    double sqSize = (double) getHeight() / N_ROWS;
    for (int i = 0; i < N_ROWS; i++) {
    for (int j = 0; j < N_COLUMNS; j++) {
    double x = j * sqSize;
    double y = i * sqSize;
    GRect sq = new GRect(x, y, sqSize, sqSize);
    sq.setFilled((i + j) % 2 != 0);
    sq.setColor(Color.GRAY);
    add(sq);

    for (i=0;i<rows;i++) {
    if (i>3 and i<6) continue; //says there is a parentheses error here?
    for j=0;j<cols;j++ {
    if (i+j %2 =0) addchecker()
    }
    }

    void addchecker()
    {
    }
    }
    }
    }

    private static final int N_ROWS = 8;
    private static final int N_COLUMNS = 8;


    }

    What do you all think is wrong with it? The overall goal of this program is to place black and red checkers on the checkerboard. Checkers are to be added only in rows 1, 2, 3, 6, 7 and 8. So if using loops, this corresponds to i = 0,1,2,5,6 and 7 (i representing the row number). What would be a good switch-statement to write for this?? Btw, first three rows (top) should be red, and last three (bottom) should be black. Possibly an if statement here?

    One more thing, how do I center my checkerboard in the window?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help with Checkerboard GraphicsProgram (Due Tomorrow!)

    What do you all think is wrong with it?
    One problem is that the addchecker method doesn't do anything.

    Please copy and paste here all of the error messages you are getting.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help with Checkerboard GraphicsProgram (Due Tomorrow!)

    Suggested reading:
    http://www.javaprogrammingforums.com...e-posting.html
    How To Ask Questions The Smart Way
    And this is your second post that you have labeled 'due tomorrow' with an exclamation point. I suggest you read the section in the above link regarding marking threads as urgent - statements such as this often cause contributors to avoid such posts

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with Checkerboard GraphicsProgram (Due Tomorrow!)

    More recommended reading: http://www.javaprogrammingforums.com...e-posting.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Need help on an Assignment but its due tomorrow!
    By Mob31 in forum Paid Java Projects
    Replies: 1
    Last Post: March 2nd, 2011, 06:54 AM