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 2 of 2

Thread: Need switch statement for checker game (DUE TOMORROW!)

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

    Default Need switch statement for checker game (DUE TOMORROW!)

    I need to add checkers to my checkerboard.

    A checker is added only in rows 1,2,3,6,7 and 8. If using a loop, this corresponds to i = 0,1,2,5,6 and 7.

    I need help writing a switch statement to place checkers on my checkerboard.

    Here is the code for my checkerboard.

    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);
    }
    }
    }
    }

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


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Need switch statement for checker game (DUE TOMORROW!)

    Let me google that for you
    The switch Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. How do I loop a switch Statement?
    By Arkeshen in forum Java Theory & Questions
    Replies: 10
    Last Post: August 2nd, 2018, 07:47 AM
  2. How to Use the Java switch statement
    By JavaPF in forum Java Programming Tutorials
    Replies: 6
    Last Post: April 18th, 2013, 05:19 PM
  3. Advancing day w/ if/else & switch statement
    By rbread80 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 31st, 2010, 10:43 PM
  4. help with switch statement
    By robertsbd in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 12th, 2010, 12:52 PM
  5. [SOLVED] Switch statement question
    By shikh_albelad in forum Loops & Control Statements
    Replies: 5
    Last Post: May 31st, 2009, 05:13 AM