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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: Waddle the Java Jedi Penguin needs help with assignment.

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Question Waddle the Java Jedi Penguin needs help with assignment.

    I need to make some sort of algorithm for chess pieces. I need a king, which can move 1 square in any direction. I need a knight which can move one square forward, though forward is defined differently for each color, and one to the left, or the right, one forward, and two to the left or right, etc, a rook which can move basically along the x and y axis, a bishop which basically moves along the lines x = y and x = - y. And a queen which can move either like the bishop or like the rook.

    I have an 8 by 8 grid and want to know how to make it check how each piece moves legally within that grid.



  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    Calculate the path along which the piece is moving and check to see if that place is empty (I'd suggest integer math because it gets rid of all floating math guess-work). In the case of the knight you only need to check the spot it's attempting to move to.

    Ex (for a rook):
    current position = rook's current row and col
    target position = potential destination
    board = 8*8 chess board
    if current position = target position:
       attempting to move to the same spot, can't move
    else if target position is out of bounds (row or col < 0 or >= 8):
       invalid move (moving outside the board)
    else if target row = current row:
        for every col between target col and current col (not including current col):
            if (current row, col) is not empty:
                 invalid move, we have something blocking the way
    else if target col = current col:
        for every row between target row and current row (not including current row):
            if (row, current col) is not empty:
                invalid move, we have something blocking the way
    else
       invalid move (some sort of diagonal movement)

  3. The Following 2 Users Say Thank You to helloworld922 For This Useful Post:

    javapenguin (September 18th, 2010), JavaPF (September 20th, 2010)

  4. #3
    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: Waddle the Java Jedi Penguin needs help with assignment.

    You left off the pawns. There are more of them than all the other pieces.

  5. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    Quote Originally Posted by helloworld922 View Post
    Calculate the path along which the piece is moving and check to see if that place is empty (I'd suggest integer math because it gets rid of all floating math guess-work). In the case of the knight you only need to check the spot it's attempting to move to.

    Ex (for a rook):
    current position = rook's current row and col
    target position = potential destination
    board = 8*8 chess board
    if current position = target position:
       attempting to move to the same spot, can't move
    else if target position is out of bounds (row or col < 0 or >= 8):
       invalid move (moving outside the board)
    else if target row = current row:
        for every col between target col and current col (not including current col):
            if (current row, col) is not empty:
                 invalid move, we have something blocking the way
    else if target col = current col:
        for every row between target row and current row (not including current row):
            if (row, current col) is not empty:
                invalid move, we have something blocking the way
    else
       invalid move (some sort of diagonal movement)
    No idea how to check if something is blocking the way. Only knights can jump over stuff in the way. But I don't have to do that. Just be able to choose which piece it is, its color, its current position, and if the position it wants to move to is valid.

    That'd be cool though if I knew how to deal with it blocking the way, but right now I need this stuff first, and I can alter it after the assignment is due.

    Also, a bishop moves along the lines x = y and x = - y.

    So for (x,y) It'd have (x+n, y+n), (x+n, y-n) , (x-n, y+n), and (x - n, y - n) as valid moves.

    Due to the way I've set it up, I can make sure that the moves selected will be in range of the board ans o it won't tell the user that a move off of the board is valid.

  6. #5
    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: Waddle the Java Jedi Penguin needs help with assignment.

    An approach:
    Have a method that given a location and piece would return a list of all the possible paths that a piece could move on. The path would consist of a list of squares that the piece could move to.
    Then search each of those paths to see if there was a blockage. For a rook there would be 4 possible paths: N, S, E and W. The bishop would also have 4 paths along the diagonals The pawn 1 path. The King 8 but only 1 unit long.

  7. The Following User Says Thank You to Norm For This Useful Post:

    JavaPF (September 20th, 2010)

  8. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    import java.util.*;
    import java.io.*;
     
    // This program will ask the user to choose a chess piece.  Either a King, 'G' or 'g',
    // a Rook, 'R' or 'r', a Bishop, 'B' or 'b', a Knight, 'K' or 'k', a Pawn, 'P' or 'p',
    // a Queen, 'Q' or 'q', or Exit, 'X' or 'x'.  My while loops should make sure that it 
    // doesn't send someone back to the beginning if they've entered a valid piece and color
    // but not a valid current position or new position.  It won't accept coords outside of
    // range so the isValid(Point pt) will never be called unless the coordinates are valid,
    // that way it won't tell the user that a move off of the board is a valid move.
     
     
    public class TestChessGame 
    { // beginning of program
     
    static Scanner console = new Scanner(System.in);
     
    public static void main(String[] args)
    { // beginning of main
     
     
     
    // char variable used to select chess pieces or exit.  Initialized to 'c' just in case
    // my while loop coming up throws a Null Pointer Exception if I don't.
    char p = 'c';
     
    char color = 'C';  
     
     
    // this while loop should make sure that it'll continue to ask the user for input until
    // they enter either a 'x' or a 'X'.
    while (p != 'x' || p != 'X')
    { // beginning of while
     
    // boolean used for while loop
    boolean isAValidChar = false;
     
    while(isAValidChar == false)
    { // beginning of while
    // creates menu 
    System.out.println("Select a piece or exit.");
    System.out.println("G = King");
    System.out.println("R = Rook");
    System.out.println("B = Bishop");
    System.out.println("K = Knight");
    System.out.println("P = Pawn");
    System.out.println("Q = Queen");
    System.out.printnln("X = Exit");
     
    // sets put to user input value
     
    // will ask user for a char till they enter one
    try{ // beginning of try
     
    p = console.nextChar();
    isAValidChar = true;
    } // end of try
     
    // will handle an Input Mismatch Exception
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // allows for lowercase and uppercase to be more user-friendly
    if (p == 'G' || p == 'g')
    { // beginning of if
     
    // creates a new King object
    King k = new King();
     
     
    // boolean used for while loop
    boolean isValidColor = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar2 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar2 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.nextChar();
     
    isAValidChar2 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == 'W' || color == 'w')
    { // beginning of if 
     
    // sets the color of the King to white
    k.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for King's position.");
     
    // user input for row for current position
     
    int x = console.nextInt();
    isValidX = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean isValidY = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidY == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for King's position.");
     
    // user input for column for current position
    int y = console.nextInt();
    isValidY = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords to false and so asks the user to enter the coordinates again
     
    if (x < 0 || x > 7 || y < 0 || y > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor 
    // will be set to true so it won't ask that again.
     
    isValidCords = false;
    isValidColor = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt = new Point(x,y);
     
    k.setPosition(pt);
     
    // boolean used to check for try/catch block while loop for a valid int x value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords2 = false;
     
    while (isValidCords2 == false)
    { // beginning of while 
     
    boolean isValidX2 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX2 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for King's new position.");
     
    // user input for row for King's new position
    int x2 = console.nextInt();
     
    isValidX2 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean isValidY2 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidY2 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for King's new position.");
     
    // user input for column for King's new position
    int y2 = console.nextInt();
     
    isValidY2 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x2 < 0 || x2 > 7 || y2 < 0 || y2 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords2 to false, but isValidColor and isValidCords are true
    // so those two won't have to be asked for again.
     
    isValidCords2 = false;
    isValidCords = true;
    isValidColor = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt2 = new Point(x2, y2);
     
    k.setNewPosition(pt2);
     
    System.out.println(k.toString());
     
    isValidCords2 = true;
    isValidCords = true;
    isValidColor = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
     
    // if color is black
    else if (color == 'B' || color == 'b')
    { // beginning of else if
     
    // sets the color of the King to white
    k.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords3 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords3 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX3 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX3 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for King's position.");
     
    // user input for row for current position
     
    int x3 = console.nextInt();
    isValidX3 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean isValidY3 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidY3 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for King's position.");
     
    // user input for column for current position
    int y3 = console.nextInt();
    isValidY3 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords to false and so asks the user to enter the coordinates again
     
    if (x3 < 0 || x3 > 7 || y3 < 0 || y3 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords3 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor 
    // will be set to true so it won't ask that again.
     
    isValidCords3 = false;
    isValidColor = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt3 = new Point(x3,y3);
     
    k.setPosition(pt3);
     
    // boolean used to check for try/catch block while loop for a valid int x value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords4 = false;
     
    while (isValidCords4 == false)
    { // beginning of while 
     
    boolean isValidX4 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX4 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for King's new position.");
     
    // user input for row for King's new position
    int x4 = console.nextInt();
     
    isValidX4 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean isValidY4 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidY4 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for King's new position.");
     
    // user input for column for King's new position
    int y4 = console.nextInt();
     
    isValidY4 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x4 < 0 || x4 > 7 || y4 < 0 || y4 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords4 to false, but isValidColor and isValidCords3 are true
    // so those two won't have to be asked for again.
     
    isValidCords4 = false;
    isValidCords3 = true;
    isValidColor = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt4 = new Point(x4, y4);
     
    k.setNewPosition(pt4);
     
    System.out.println(k.toString());
     
    isValidCords4 = true;
    isValidCords3 = true;
    isValidColor = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor = false;
    } // end of else
     
    } // end of while
     
    } // end of if
     
    // if the piece is a Pawn
    else if (p == 'P' || p == 'p')
    { // beginning of else if
     
    // creates a new Pawn
    Pawn pwn = new Pawn(); 
     
     
    // boolean used for while loop
    boolean isValidColor2 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor2 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar3 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar3 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.nextChar();
     
    isAValidChar3 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == 'W' || color == 'w')
    { // beginning of if 
     
    // sets the color of the Pawn to white
    pwn.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords5 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords5 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX5 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX5 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Pawn's position.");
     
    // user input for row for current position
     
    int x5 = console.nextInt();
    isValidX5 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY5 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY5 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Pawn's position.");
     
    // user input for column for current position
    int y5 = console.nextInt();
    IsValidY5 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords5 to false and so asks the user to enter the coordinates again
     
    if (x5 < 0 || x5 > 7 || y5 < 0 || y5 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords5 = false;
    isValidColor2 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt5 = new Point(x5,y5);
     
    pwn.setPosition(pt5);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords6 = false
     
    while (isValidCords6 == false)
    { // beginning of while 
     
    boolean isValidX6 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX6 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Pawn's new position.");
     
    // user input for row for Pawn's new position
    int x6 = console.nextInt();
     
    isValidX6 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY6 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY6 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Pawn's new position.");
     
    // user input for column for Pawn's new position
    int y6 = console.nextInt();
     
    IsValidY6 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x6 < 0 || x6 > 7 || y6 < 0 || y6 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords6 = false;
    isValidCords5 = true;
    isValidColor2 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt6 = new Point(x6, y6);
     
    pwn.setNewPosition(pt2);
     
    System.out.println(pwn.toString());
     
    isValidCords6 = true;
    isValidCords5 = true;
    isValidColor2 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
     
    // if color is black
    else if (color == 'B' || color == 'b')
    { // beginning of else if
     
    // sets the color of the Pawn to white
    pwn.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords7 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords7 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX7 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX7 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Pawn's position.");
     
    // user input for row for current position
     
    int x7 = console.nextInt();
    isValidX7 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY7 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY7 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Pawn's position.");
     
    // user input for column for current position
    int y7 = console.nextInt();
    IsValidY7 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords5 to false and so asks the user to enter the coordinates again
     
    if (x7 < 0 || x7 > 7 || y7 < 0 || y7 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords7 = false;
    isValidColor2 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt7 = new Point(x7,y7);
     
    pwn.setPosition(pt7);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords8 = false;
     
    while (isValidCords8 == false)
    { // beginning of while 
     
    boolean isValidX8 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX8 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Pawn's new position.");
     
    // user input for row for Pawn's new position
    int x8 = console.nextInt();
     
    isValidX8 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY8 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY8 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Pawn's new position.");
     
    // user input for column for Pawn's new position
    int y8 = console.nextInt();
     
    IsValidY8 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x8 < 0 || x8 > 7 || y8 < 0 || y8 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor2 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords8 = false;
    isValidCords7 = true;
    isValidColor2 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt8 = new Point(x8, y8);
     
    pwn.setNewPosition(pt8);
     
    System.out.println(pwn.toString());
     
    isValidCords8 = true;
    isValidCords7 = true;
    isValidColor2 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor2 = false;
    } // end of else
     
    } // end of while
     
    } // end of else if
     
    // if the piece is a Rook
     
    else if (p == 'R' || p == 'r')
    { // beginning of else if
     
    // creates a new Rook
     
    Rook r = new Rook();
     
    // boolean used for while loop
    boolean isValidColor3 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor3 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar4 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar4 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.nextChar();
     
    isAValidChar4 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == 'W' || color == 'w')
    { // beginning of if 
     
    // sets the color of the Rook to white
    r.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords9 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords9 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX9 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX9 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Rook's position.");
     
    // user input for row for current position
     
    int x9 = console.nextInt();
    isValidX9 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY9 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY9 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Rook's position.");
     
    // user input for column for current position
    int y9 = console.nextInt();
    IsValidY9 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords9 to false and so asks the user to enter the coordinates again
     
    if (x9 < 0 || x9 > 7 || y9 < 0 || y9 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor3 
    // will be set to true so it won't ask that again.
     
    isValidCords9 = false;
    isValidColor3 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt9 = new Point(x9,y9);
     
    r.setPosition(pt9);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords10 = false
     
    while (isValidCords10 == false)
    { // beginning of while 
     
    boolean isValidX10 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX10 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Rook's new position.");
     
    // user input for row for Rook's new position
    int x10 = console.nextInt();
     
    isValidX10 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY10 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY10 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Rook's new position.");
     
    // user input for column for Rook's new position
    int y10 = console.nextInt();
     
    IsValidY10 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x10 < 0 || x10 > 7 || y10 < 0 || y10 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords10 = false;
    isValidCords9 = true;
    isValidColor3 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt10 = new Point(x10, y10);
     
    r.setNewPosition(pt10);
     
    System.out.println(r.toString());
     
    isValidCords10 = true;
    isValidCords9 = true;
    isValidColor3 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
     
    // if color is black
    else if (color == 'B' || color == 'b')
    { // beginning of else if
     
    // sets the color of the Rook to white
    r.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords11 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords11 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX11 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX11 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Rook's position.");
     
    // user input for row for current position
     
    int x11 = console.nextInt();
    isValidX11 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY11 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY11 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Rook's position.");
     
    // user input for column for current position
    int y11 = console.nextInt();
    IsValidY11 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords11 to false and so asks the user to enter the coordinates again
     
    if (x11 < 0 || x11 > 7 || y11 < 0 || y11 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords11 = false;
    isValidColor3 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt11 = new Point(x11,y11);
     
    r.setPosition(pt11);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords12 = false;
     
    while (isValidCords12 == false)
    { // beginning of while 
     
    boolean isValidX12 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX12 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Rook's new position.");
     
    // user input for row for Rook's new position
    int x12 = console.nextInt();
     
    isValidX12 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY12 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY12 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Rook's new position.");
     
    // user input for column for Rook's new position
    int y12 = console.nextInt();
     
    IsValidY12 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x12 < 0 || x12 > 7 || y12 < 0 || y12 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor3 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords12 = false;
    isValidCords11 = true;
    isValidColor3 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt12 = new Point(x12, y12);
     
    r.setNewPosition(pt12);
     
    System.out.println(r.toString());
     
    isValidCords12 = true;
    isValidCords11 = true;
    isValidColor3 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor3 = false;
    } // end of else
     
    } // end of while
     
     
    } // end of else if
     
    // if the piece is a Bishop
     
    else if (p == 'B' || p == 'b')
    { // beginning of else if
     
    // creates a new Bishop
     
    Bishop b = new Bishop();
    // boolean used for while loop
    boolean isValidColor4 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor4 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar5 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar5 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.nextChar();
     
    isAValidChar5 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == 'W' || color == 'w')
    { // beginning of if 
     
    // sets the color of the Bishop to white
    b.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords13 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords13 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX13 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX13 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Bishop's position.");
     
    // user input for row for current position
     
    int x13 = console.nextInt();
    isValidX13 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY13 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY13 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Bishop's position.");
     
    // user input for column for current position
    int y13 = console.nextInt();
    IsValidY13 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords13 to false and so asks the user to enter the coordinates again
     
    if (x13 < 0 || x13 > 7 || y13 < 0 || y13 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor3 
    // will be set to true so it won't ask that again.
     
    isValidCords13 = false;
    isValidColor4 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt13 = new Point(x13,y13);
     
    b.setPosition(pt13);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords14 = false
     
    while (isValidCords14 == false)
    { // beginning of while 
     
    boolean isValidX14 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX14 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Bishop's new position.");
     
    // user input for row for Bishop's new position
    int x14 = console.nextInt();
     
    isValidX14 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY14 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY14 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Bishop's new position.");
     
    // user input for column for Bishop's new position
    int y14 = console.nextInt();
     
    IsValidY14 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x14 < 0 || x14 > 7 || y14 < 0 || y14 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords14 = false;
    isValidCords13 = true;
    isValidColor4 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt14 = new Point(x14, y14);
     
    b.setNewPosition(pt14);
     
    System.out.println(b.toString());
     
    isValidCords14 = true;
    isValidCords13 = true;
    isValidColor4 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
     
    // if color is black
    else if (color == 'B' || color == 'b')
    { // beginning of else if
     
    // sets the color of the Bishop to white
    b.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords15 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords15 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX15 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX15 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Bishop's position.");
     
    // user input for row for current position
     
    int x15 = console.nextInt();
    isValidX15 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY15 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY15 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Bishop's position.");
     
    // user input for column for current position
    int y15 = console.nextInt();
    IsValidY15 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords11 to false and so asks the user to enter the coordinates again
     
    if (x15 < 0 || x15 > 7 || y15 < 0 || y15 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords15 = false;
    isValidColor4 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt15 = new Point(x15,y15);
     
    b.setPosition(pt15);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords16 = false;
     
    while (isValidCords16 == false)
    { // beginning of while 
     
    boolean isValidX16 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX16 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Bishop's new position.");
     
    // user input for row for Bishop's new position
    int x16 = console.nextInt();
     
    isValidX16 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY16 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY16 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Bishop's new position.");
     
    // user input for column for Bishop's new position
    int y16 = console.nextInt();
     
    IsValidY16 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x16 < 0 || x16 > 7 || y16 < 0 || y16 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor3 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords16 = false;
    isValidCords15 = true;
    isValidColor4 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt16 = new Point(x16, y16);
     
    b.setNewPosition(pt16);
     
    System.out.println(b.toString());
     
    isValidCords16 = true;
    isValidCords15 = true;
    isValidColor4 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor4 = false;
    } // end of else
     
    } // end of while
     
     
    } // end of else if
     
    // if the piece is a Knight
     
    else if (p == 'K' || p == 'k')
    { // beginning of else if
     
    // creates a new Knight
     
    Knight kn = new Knight();
     
    // boolean used for while loop
    boolean isValidColor5 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor5 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar6 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar6 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.nextChar();
     
    isAValidChar6 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == 'W' || color == 'w')
    { // beginning of if 
     
    // sets the color of the Knight to white
    kn.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords17 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords17 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX17 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX17 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Knight's position.");
     
    // user input for row for current position
     
    int x17 = console.nextInt();
    isValidX17 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY17 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY17 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Knight's position.");
     
    // user input for column for current position
    int y17 = console.nextInt();
    IsValidY17 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords17 to false and so asks the user to enter the coordinates again
     
    if (x17 < 0 || x17 > 7 || y17 < 0 || y17 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor3 
    // will be set to true so it won't ask that again.
     
    isValidCords17 = false;
    isValidColor5 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt17 = new Point(x17,y17);
     
    kn.setPosition(pt17);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords18 = false
     
    while (isValidCords18 == false)
    { // beginning of while 
     
    boolean isValidX18 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX18 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Knight's new position.");
     
    // user input for row for Knight's new position
    int x18 = console.nextInt();
     
    isValidX18 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY18 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY18 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Knight's new position.");
     
    // user input for column for Knight's new position
    int y18 = console.nextInt();
     
    IsValidY18 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x18 < 0 || x18 > 7 || y18 < 0 || y18 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords18 = false;
    isValidCords17 = true;
    isValidColor5 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt18 = new Point(x18, y18);
     
    kn.setNewPosition(pt18);
     
    System.out.println(kn.toString());
     
    isValidCords18 = true;
    isValidCords17 = true;
    isValidColor5 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
     
    // if color is black
    else if (color == 'B' || color == 'b')
    { // beginning of else if
     
    // sets the color of the Knight to white
    kn.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords19 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords19 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX19 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX19 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Knight's position.");
     
    // user input for row for current position
     
    int x19 = console.nextInt();
    isValidX19 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY19 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY19 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Knight's position.");
     
    // user input for column for current position
    int y19 = console.nextInt();
    IsValidY19 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords11 to false and so asks the user to enter the coordinates again
     
    if (x19 < 0 || x19 > 7 || y19 < 0 || y19 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords19 = false;
    isValidColor5 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt19 = new Point(x19,y19);
     
    kn.setPosition(pt19);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords20 = false;
     
    while (isValidCords20 == false)
    { // beginning of while 
     
    boolean isValidX20 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX20 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Knight's new position.");
     
    // user input for row for Knight's new position
    int x20 = console.nextInt();
     
    isValidX20 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY20 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY20 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Knight's new position.");
     
    // user input for column for Knight's new position
    int y20 = console.nextInt();
     
    IsValidY20 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x20 < 0 || x20 > 7 || y20 < 0 || y20 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor3 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords20 = false;
    isValidCords19 = true;
    isValidColor5 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt20 = new Point(x20, y20);
     
    kn.setNewPosition(pt20);
     
    System.out.println(kn.toString());
     
    isValidCords20 = true;
    isValidCords15 = true;
    isValidColor5 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor5 = false;
    } // end of else
     
    } // end of while
     
     
    } // end of else if
     
    // if the piece is a Queen
     
    else if (p == 'Q' || p == 'q')
    { // beginning of else if
     
    // creates a new Queen
     
    Queen q = new Queen();
     
    // boolean used for while loop
    boolean isValidColor6 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor6 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar7 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar7 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.nextChar();
     
    isAValidChar7 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == 'W' || color == 'w')
    { // beginning of if 
     
    // sets the color of the Queen to white
    q.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords21 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords21 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX21 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX21 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Queen's position.");
     
    // user input for row for current position
     
    int x21 = console.nextInt();
    isValidX21 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY21 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY21 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Queen's position.");
     
    // user input for column for current position
    int y21 = console.nextInt();
    IsValidY21 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords17 to false and so asks the user to enter the coordinates again
     
    if (x21 < 0 || x21 > 7 || y21 < 0 || y21 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor3 
    // will be set to true so it won't ask that again.
     
    isValidCords21 = false;
    isValidColor6 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt21 = new Point(x21,y21);
     
    q.setPosition(pt21);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords22 = false
     
    while (isValidCords22 == false)
    { // beginning of while 
     
    boolean isValidX22 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX22 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Queen's new position.");
     
    // user input for row for Queen's new position
    int x22 = console.nextInt();
     
    isValidX22 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY22 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY22 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Queen's new position.");
     
    // user input for column for Queen's new position
    int y22 = console.nextInt();
     
    IsValidY22 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x22 < 0 || x22 > 7 || y22 < 0 || y22 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords22 = false;
    isValidCords21 = true;
    isValidColor6 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt22 = new Point(x22, y22);
     
    q.setNewPosition(pt22);
     
    System.out.println(q.toString());
     
    isValidCords22 = true;
    isValidCords21 = true;
    isValidColor6 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
     
    // if color is black
    else if (color == 'B' || color == 'b')
    { // beginning of else if
     
    // sets the color of the Queen to white
    q.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords23 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords23 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX23 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX23 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Queen's position.");
     
    // user input for row for current position
     
    int x23 = console.nextInt();
    isValidX23 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY23 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY23 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Queen's position.");
     
    // user input for column for current position
    int y23 = console.nextInt();
    IsValidY23 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords11 to false and so asks the user to enter the coordinates again
     
    if (x23 < 0 || x23 > 7 || y23 < 0 || y23 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords23 = false;
    isValidColor6 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt23 = new Point(x23,y23);
     
    q.setPosition(pt23);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords24 = false;
     
    while (isValidCords24 == false)
    { // beginning of while 
     
    boolean isValidX24 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX24 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Queen's new position.");
     
    // user input for row for Queen's new position
    int x24 = console.nextInt();
     
    isValidX24 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY24 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY24 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Queen's new position.");
     
    // user input for column for Queen's new position
    int y24 = console.nextInt();
     
    IsValidY24 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x24 < 0 || x24 > 7 || y24 < 0 || y24 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor3 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords24 = false;
    isValidCords23 = true;
    isValidColor6 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt24 = new Point(x24, y24);
     
    q.setNewPosition(pt24);
     
    System.out.println(q.toString());
     
    isValidCords24 = true;
    isValidCords23 = true;
    isValidColor6 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor6 = false;
    } // end of else
     
    } // end of while
     
     
     
    } // end of else if
     
    // if the user exits
     
    else if (p == 'X' || p == 'x')
    { // beginning of else if
     
    System.exit(0);
     
    } // end of else if
     
     
    // if the user enters a char but not one of the ones on the menu 
    else
    System.out.println("Make a valid selection.");
     
    } // end of while
     
    } // end of main
     
    } // end of program

    b

  9. #7
    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: Waddle the Java Jedi Penguin needs help with assignment.

    Are there any questions or comment now? Is this the final working program? Problem solved?

  10. #8
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    Why can't it find most of my x and y variables?
    It's copy and paste, so what's wrong with the first set will be wrong with all, or most, of them.

    I fixed the duplicate program beginning stuff, I think, though I'm not sure what's wrong now.

    package Chess;
     
    import java.util.*;
    import java.io.*;
    import java.awt.Point;
     
     
    // This program will ask the user to choose a chess piece.  Either a King, 'G' or 'g',
    // a Rook, 'R' or 'r', a Bishop, 'B' or 'b', a Knight, 'K' or 'k', a Pawn, 'P' or 'p',
    // a Queen, 'Q' or 'q', or Exit, 'X' or 'x'.  My while loops should make sure that it 
    // doesn't send someone back to the beginning if they've entered a valid piece and color
    // but not a valid current position or new position.  It won't accept coords outside of
    // range so the isValid(Point pt) will never be called unless the coordinates are valid,
    // that way it won't tell the user that a move off of the board is a valid move.
     
     
    public class TestChessGame 
    { // beginning of program
     
    	 static Scanner console = new Scanner(System.in);
     
     
    public static void main(String[] args)
    { // beginning of main
     
     
     
     
    // char variable used to select chess pieces or exit.  Initialized to 'c' just in case
    // my while loop coming up throws a Null Pointer Exception if I don't.
    String p = "c";
     
    String color = "C";  
     
     
    // this while loop should make sure that it'll continue to ask the user for input until
    // they enter either a 'x' or a 'X'.
    while (p != "x" || p != "X")
    { // beginning of while
     
    // boolean used for while loop
    boolean isAValidChar = false;
     
    while(isAValidChar == false)
    { // beginning of while
    // creates menu 
    System.out.println("Select a piece or exit.");
    System.out.println("G = King");
    System.out.println("R = Rook");
    System.out.println("B = Bishop");
    System.out.println("K = Knight");
    System.out.println("P = Pawn");
    System.out.println("Q = Queen");
    System.out.println("X = Exit");
     
    // sets put to user input value
     
    // will ask user for a char till they enter one
    try{ // beginning of try
    String string;
    String str;
     
    p = console.next();
     
     
    isAValidChar = true;
    } // end of try
     
    // will handle an Input Mismatch Exception
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // allows for lowercase and uppercase to be more user-friendly
    if (p == "G" || p == "g")
    { // beginning of if
     
    // creates a new King object
    King k = new King();
     
     
    // boolean used for while loop
    boolean isValidColor = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar2 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar2 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.next();
     
    isAValidChar2 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == "W" || color == "w")
    { // beginning of if 
     
    // sets the color of the King to white
    k.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for King's position.");
     
    // user input for row for current position
     
    int x = console.nextInt();
    isValidX = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean isValidY = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidY == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for King's position.");
     
    // user input for column for current position
    int y = console.nextInt();
    isValidY = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords to false and so asks the user to enter the coordinates again
     
    if (x < 0 || x > 7 || y < 0 || y > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor 
    // will be set to true so it won't ask that again.
     
    isValidCords = false;
    isValidColor = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
     Point pt = new Point(x,y);
     
    k.setPosition(pt);
     
    // boolean used to check for try/catch block while loop for a valid int x value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords2 = false;
     
    while (isValidCords2 == false)
    { // beginning of while 
     
    boolean isValidX2 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX2 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for King's new position.");
     
    // user input for row for King's new position
    int x2 = console.nextInt();
     
    isValidX2 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean isValidY2 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidY2 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for King's new position.");
     
    // user input for column for King's new position
    int y2 = console.nextInt();
     
    isValidY2 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x2 < 0 || x2 > 7 || y2 < 0 || y2 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords2 to false, but isValidColor and isValidCords are true
    // so those two won't have to be asked for again.
     
    isValidCords2 = false;
    isValidCords = true;
    isValidColor = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt2 = new Point(x2, y2);
     
    k.setNewPosition(pt2);
     
    System.out.println(k.toString());
     
    isValidCords2 = true;
    isValidCords = true;
    isValidColor = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
    }
     
    // if color is black
    else if (color == "B" || color == "b")
    { // beginning of else if
     
    // sets the color of the King to white
    k.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords3 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords3 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX3 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX3 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for King's position.");
     
    // user input for row for current position
     
    int x3 = console.nextInt();
    isValidX3 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean isValidY3 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidY3 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for King's position.");
     
    // user input for column for current position
    int y3 = console.nextInt();
    isValidY3 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords to false and so asks the user to enter the coordinates again
     
    if (x3 < 0 || x3 > 7 || y3 < 0 || y3 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords3 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor 
    // will be set to true so it won't ask that again.
     
    isValidCords3 = false;
    isValidColor = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt3 = new Point(x3,y3);
     
    k.setPosition(pt3);
     
    // boolean used to check for try/catch block while loop for a valid int x value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords4 = false;
     
    while (isValidCords4 == false)
    { // beginning of while 
     
    boolean isValidX4 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX4 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for King's new position.");
     
    // user input for row for King's new position
    int x4 = console.nextInt();
     
    isValidX4 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean isValidY4 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidY4 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for King's new position.");
     
    // user input for column for King's new position
    int y4 = console.nextInt();
     
    isValidY4 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x4 < 0 || x4 > 7 || y4 < 0 || y4 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords4 to false, but isValidColor and isValidCords3 are true
    // so those two won't have to be asked for again.
     
    isValidCords4 = false;
    isValidCords3 = true;
    isValidColor = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt4 = new Point(x4, y4);
     
    k.setNewPosition(pt4);
     
    System.out.println(k.toString());
     
    isValidCords4 = true;
    isValidCords3 = true;
    isValidColor = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
    }
     
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor = false;
    } // end of else
     
    } // end of while
     
    } // end of if
     
    // if the piece is a Pawn
    else if (p == "P" || p == "p")
    { // beginning of else if
     
    // creates a new Pawn
    Pawn pwn = new Pawn(); 
     
     
    // boolean used for while loop
    boolean isValidColor2 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor2 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar3 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar3 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.next();
     
    isAValidChar3 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == "W" || color == "w")
    { // beginning of if 
     
    // sets the color of the Pawn to white
    pwn.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords5 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords5 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX5 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX5 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Pawn's position.");
     
    // user input for row for current position
     
    int x5 = console.nextInt();
    isValidX5 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY5 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY5 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Pawn's position.");
     
    // user input for column for current position
    int y5 = console.nextInt();
    IsValidY5 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords5 to false and so asks the user to enter the coordinates again
     
    if (x5 < 0 || x5 > 7 || y5 < 0 || y5 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords5 = false;
    isValidColor2 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt5 = new Point(x5,y5);
     
    pwn.setPosition(pt5);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords6 = false;
     
    while (isValidCords6 == false)
    { // beginning of while 
     
    boolean isValidX6 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX6 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Pawn's new position.");
     
    // user input for row for Pawn's new position
    int x6 = console.nextInt();
     
    isValidX6 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY6 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY6 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Pawn's new position.");
     
    // user input for column for Pawn's new position
    int y6 = console.nextInt();
     
    IsValidY6 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x6 < 0 || x6 > 7 || y6 < 0 || y6 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords6 = false;
    isValidCords5 = true;
    isValidColor2 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt6 = new Point(x6, y6);
     
    pwn.setNewPosition(pt2);
     
    System.out.println(pwn.toString());
     
    isValidCords6 = true;
    isValidCords5 = true;
    isValidColor2 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
    }
     
     
    // if color is black
    else if (color == "B" || color == "b")
    { // beginning of else if
     
    // sets the color of the Pawn to white
    pwn.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords7 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords7 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX7 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX7 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Pawn's position.");
     
    // user input for row for current position
     
    int x7 = console.nextInt();
    isValidX7 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY7 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY7 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Pawn's position.");
     
    // user input for column for current position
    int y7 = console.nextInt();
    IsValidY7 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords5 to false and so asks the user to enter the coordinates again
     
    if (x7 < 0 || x7 > 7 || y7 < 0 || y7 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords7 = false;
    isValidColor2 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt7 = new Point(x7,y7);
     
    pwn.setPosition(pt7);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords8 = false;
     
    while (isValidCords8 == false)
    { // beginning of while 
     
    boolean isValidX8 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX8 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Pawn's new position.");
     
    // user input for row for Pawn's new position
    int x8 = console.nextInt();
     
    isValidX8 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY8 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY8 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Pawn's new position.");
     
    // user input for column for Pawn's new position
    int y8 = console.nextInt();
     
    IsValidY8 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x8 < 0 || x8 > 7 || y8 < 0 || y8 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor2 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords8 = false;
    isValidCords7 = true;
    isValidColor2 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt8 = new Point(x8, y8);
     
    pwn.setNewPosition(pt8);
     
    System.out.println(pwn.toString());
     
    isValidCords8 = true;
    isValidCords7 = true;
    isValidColor2 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
    }
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor2 = false;
    } // end of else
     
    } // end of while
     
    } // end of else if
     
    // if the piece is a Rook
     
    else if (p == "R" || p == "r")
    { // beginning of else if
     
    // creates a new Rook
     
    Rook r = new Rook();
     
    // boolean used for while loop
    boolean isValidColor3 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor3 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar4 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar4 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.next();
     
    isAValidChar4 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == "W" || color == "w")
    { // beginning of if 
     
    // sets the color of the Rook to white
    r.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords9 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords9 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX9 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX9 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Rook's position.");
     
    // user input for row for current position
     
    int x9 = console.nextInt();
    isValidX9 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY9 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY9 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Rook's position.");
     
    // user input for column for current position
    int y9 = console.nextInt();
    IsValidY9 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords9 to false and so asks the user to enter the coordinates again
     
    if (x9 < 0 || x9 > 7 || y9 < 0 || y9 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor3 
    // will be set to true so it won't ask that again.
     
    isValidCords9 = false;
    isValidColor3 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt9 = new Point(x9,y9);
     
    r.setPosition(pt9);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords10 = false;
     
    while (isValidCords10 == false)
    { // beginning of while 
     
    boolean isValidX10 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX10 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Rook's new position.");
     
    // user input for row for Rook's new position
    int x10 = console.nextInt();
     
    isValidX10 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY10 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY10 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Rook's new position.");
     
    // user input for column for Rook's new position
    int y10 = console.nextInt();
     
    IsValidY10 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x10 < 0 || x10 > 7 || 0 > y10 || y10 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords10 = false;
    isValidCords9 = true;
    isValidColor3 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt10 = new Point(x10, y10);
     
    r.setNewPosition(pt10);
     
    System.out.println(r.toString());
     
    isValidCords10 = true;
    isValidCords9 = true;
    isValidColor3 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
    }
     
    // if color is black
    else if (color == "b" || color == "b")
    { // beginning of else if
     
    // sets the color of the Rook to white
    r.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords11 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords11 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX11 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX11 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Rook's position.");
     
    // user input for row for current position
     
    int x11 = console.nextInt();
    isValidX11 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY11 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY11 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Rook's position.");
     
    // user input for column for current position
    int y11 = console.nextInt();
    IsValidY11 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords11 to false and so asks the user to enter the coordinates again
     
    if (x11 < 0 || x11 > 7 || y11 < 0 || y11 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords11 = false;
    isValidColor3 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt11 = new Point(x11,y11);
     
    r.setPosition(pt11);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords12 = false;
     
    while (isValidCords12 == false)
    { // beginning of while 
     
    boolean isValidX12 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX12 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Rook's new position.");
     
    // user input for row for Rook's new position
    int x12 = console.nextInt();
     
    isValidX12 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY12 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY12 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Rook's new position.");
     
    // user input for column for Rook's new position
    int y12 = console.nextInt();
     
    IsValidY12 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
     
    if (x12 < 0 || x12 > 7 || y12 < 0 || y12 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor3 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords12 = false;
    isValidCords11 = true;
    isValidColor3 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt12 = new Point(x12, y12);
     
    r.setNewPosition(pt12);
     
    System.out.println(r.toString());
     
    isValidCords12 = true;
    isValidCords11 = true;
    isValidColor3 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
    }
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor3 = false;
    } // end of else
     
    } // end of while
     
     
    } // end of else if
     
    // if the piece is a Bishop
     
    else if (p == "b" || p == "b")
    { // beginning of else if
     
    // creates a new Bishop
     
    Bishop b = new Bishop();
    // boolean used for while loop
    boolean isValidColor4 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor4 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar5 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar5 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.next();
     
    isAValidChar5 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == "W" || color == "w")
    { // beginning of if 
     
    // sets the color of the Bishop to white
    b.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords13 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords13 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX13 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX13 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Bishop's position.");
     
    // user input for row for current position
     
    int x13 = console.nextInt();
    isValidX13 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY13 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY13 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Bishop's position.");
     
    // user input for column for current position
    int y13 = console.nextInt();
    IsValidY13 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords13 to false and so asks the user to enter the coordinates again
     
    if (x13 < 0 || x13 > 7 || y13 < 0 || y13 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor3 
    // will be set to true so it won't ask that again.
     
    isValidCords13 = false;
    isValidColor4 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt13 = new Point(x13,y13);
     
    b.setPosition(pt13);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords14 = false;
     
    while (isValidCords14 == false)
    { // beginning of while 
     
    boolean isValidX14 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX14 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Bishop's new position.");
     
    // user input for row for Bishop's new position
    int x14 = console.nextInt();
     
    isValidX14 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY14 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY14 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Bishop's new position.");
     
    // user input for column for Bishop's new position
    int y14 = console.nextInt();
     
    IsValidY14 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x14 < 0 || x14 > 7 || y14 < 0 || y14 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords14 = false;
    isValidCords13 = true;
    isValidColor4 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt14 = new Point(x14, y14);
     
    b.setNewPosition(pt14);
     
    System.out.println(b.toString());
     
    isValidCords14 = true;
    isValidCords13 = true;
    isValidColor4 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
    }
     
     
    // if color is black
    else if (color == "B" || color == "b")
    { // beginning of else if
     
    // sets the color of the Bishop to white
    b.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords15 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords15 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX15 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX15 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Bishop's position.");
     
    // user input for row for current position
     
    int x15 = console.nextInt();
    isValidX15 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY15 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY15 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Bishop's position.");
     
    // user input for column for current position
    int y15 = console.nextInt();
    IsValidY15 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords11 to false and so asks the user to enter the coordinates again
     
    if (x15 < 0 || x15 > 7 || y15 < 0 || y15 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords15 = false;
    isValidColor4 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt15 = new Point(x15,y15);
     
    b.setPosition(pt15);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords16 = false;
     
    while (isValidCords16 == false)
    { // beginning of while 
     
    boolean isValidX16 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX16 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Bishop's new position.");
     
    // user input for row for Bishop's new position
    int x16 = console.nextInt();
     
    isValidX16 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY16 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY16 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Bishop's new position.");
     
    // user input for column for Bishop's new position
    int y16 = console.nextInt();
     
    IsValidY16 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x16 < 0 || x16 > 7 || y16 < 0 || y16 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor3 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
     
     
     
    boolean isValidCords16 = false;
     
    while (isValidCords16 == false)
    { // beginning of while 
     
    boolean isValidX16 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX16 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Bishop's new position.");
     
    // user input for row for Bishop's new position
    int x16 = console.nextInt();
     
    isValidX16 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY16 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY16 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Bishop's new position.");
     
    // user input for column for Bishop's new position
    int y16 = console.nextInt();
     
    IsValidY16 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x16 < 0 || x16 > 7 || y16 < 0 || y16 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor3 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords16 = false;
    isValidCords15 = true;
    isValidColor4 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt16 = new Point(x16, y16);
     
    b.setNewPosition(pt16);
     
    System.out.println(b.toString());
     
    isValidCords16 = true;
    isValidCords15 = true;
    isValidColor4 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
    }
    }
    }
     
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor4 = false;
    } // end of else
     
    } // end of while
     
     
    } // end of else if
     
    // if the piece is a Knight
     
    else if (p == 'K' || p == 'k')
    { // beginning of else if
     
    // creates a new Knight
     
    Knight kn = new Knight();
     
    // boolean used for while loop
    boolean isValidColor5 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor5 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar6 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar6 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.next();
     
    isAValidChar6 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == 'W' || color == 'w')
    { // beginning of if 
     
    // sets the color of the Knight to white
    kn.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords17 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords17 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX17 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX17 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Knight's position.");
     
    // user input for row for current position
     
    int x17 = console.nextInt();
    isValidX17 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY17 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY17 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Knight's position.");
     
    // user input for column for current position
    int y17 = console.nextInt();
    IsValidY17 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords17 to false and so asks the user to enter the coordinates again
     
    if (x17 < 0 || x17 > 7 || y17 < 0 || y17 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor3 
    // will be set to true so it won't ask that again.
     
    isValidCords17 = false;
    isValidColor5 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt17 = new Point(x17,y17);
     
    kn.setPosition(pt17);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords18 = false;
     
    while (isValidCords18 == false)
    { // beginning of while 
     
    boolean isValidX18 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX18 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Knight's new position.");
     
    // user input for row for Knight's new position
    int x18 = console.nextInt();
     
    isValidX18 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY18 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY18 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Knight's new position.");
     
    // user input for column for Knight's new position
    int y18 = console.nextInt();
     
    IsValidY18 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x18 < 0 || x18 > 7 || y18 < 0 || y18 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords18 = false;
    isValidCords17 = true;
    isValidColor5 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt18 = new Point(x18, y18);
     
    kn.setNewPosition(pt18);
     
    System.out.println(kn.toString());
     
    isValidCords18 = true;
    isValidCords17 = true;
    isValidColor5 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
    }
     
     
    // if color is black
    else if (color == 'B' || color == 'b')
    { // beginning of else if
     
    // sets the color of the Knight to white
    kn.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords19 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords19 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX19 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX19 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Knight's position.");
     
    // user input for row for current position
     
    int x19 = console.nextInt();
    isValidX19 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY19 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY19 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Knight's position.");
     
    // user input for column for current position
    int y19 = console.nextInt();
    IsValidY19 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords11 to false and so asks the user to enter the coordinates again
     
    if (x19 < 0 || x19 > 7 || y19 < 0 || y19 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords19 = false;
    isValidColor5 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt19 = new Point(x19,y19);
     
    kn.setPosition(pt19);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords20 = false;
     
    while (isValidCords20 == false)
    { // beginning of while 
     
    boolean isValidX20 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX20 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Knight's new position.");
     
    // user input for row for Knight's new position
    int x20 = console.nextInt();
     
    isValidX20 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY20 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY20 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Knight's new position.");
     
    // user input for column for Knight's new position
    int y20 = console.nextInt();
     
    IsValidY20 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x20 < 0 || x20 > 7 || y20 < 0 || y20 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor3 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords20 = false;
    isValidCords19 = true;
    isValidColor5 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt20 = new Point(x20, y20);
     
    kn.setNewPosition(pt20);
     
    System.out.println(kn.toString());
     
    isValidCords20 = true;
    isValidCords15 = true;
    isValidColor5 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
    }
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor5 = false;
    } // end of else
     
    } // end of while
     
     
    } // end of else if
     
    // if the piece is a Queen
     
    else if (p == 'Q' || p == 'q')
    { // beginning of else if
     
    // creates a new Queen
     
    Queen q = new Queen();
     
    // boolean used for while loop
    boolean isValidColor6 = false;
     
    // allows user to go back to this point rather than the beginning if they
    // enter an invalid color.  Also will keep asking for color till they enter a valid one.
     
    while (isValidColor6 == false)
    { // beginning of while
     
    // variable used for try/catch block while loop
    boolean isAValidChar7 = false;
     
    // will ask user for a char till they enter one
    while (isAValidChar7 == false)
    { // beginning of while
     
    try { // beginning of try
    // More asking the user for input.
    System.out.println("Choose a color.");
    System.out.println("Choose B for black or  W for White.");
     
     
    // sets color to user-entered value
    color = console.next();
     
    isAValidChar7 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
    System.out.println("Exception: " + imeRef.toString());
    }  // end of catch
     
    } // end of while
     
    // option if the color chosen is white. Isn't case sensitive.  
    if (color == 'W' || color == 'w')
    { // beginning of if 
     
    // sets the color of the Queen to white
    q.setColor("White");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords21 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords21 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX21 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX21 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Queen's position.");
     
    // user input for row for current position
     
    int x21 = console.nextInt();
    isValidX21 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY21 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY21 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Queen's position.");
     
    // user input for column for current position
    int y21 = console.nextInt();
    IsValidY21 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords17 to false and so asks the user to enter the coordinates again
     
    if (x21 < 0 || x21 > 7 || y21 < 0 || y21 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords5 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor3 
    // will be set to true so it won't ask that again.
     
    isValidCords21 = false;
    isValidColor6 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt21 = new Point(x21,y21);
     
    q.setPosition(pt21);
     
    // boolean used to check for try/catch block while loop for a valid int x5 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords22 = false;
     
    while (isValidCords22 == false)
    { // beginning of while 
     
    boolean isValidX22 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX22 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Queen's new position.");
     
    // user input for row for Queen's new position
    int x22 = console.nextInt();
     
    isValidX22 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY22 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY22 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Queen's new position.");
     
    // user input for column for Queen's new position
    int y22 = console.nextInt();
     
    IsValidY22 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x22 < 0 || x22 > 7 || y22 < 0 || y22 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords6 to false, but isValidColor2 and isValidCords5 are true
    // so those two won't have to be asked for again.
     
    isValidCords22 = false;
    isValidCords21 = true;
    isValidColor6 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt22 = new Point(x22, y22);
     
    q.setNewPosition(pt22);
     
    System.out.println(q.toString());
     
    isValidCords22 = true;
    isValidCords21 = true;
    isValidColor6 = true;
    } // end of else
     
     
     
    } // end of while
     
    } // end of while
     
    } // end of if
    }
     
    // if color is black
    else if (color == "B" || color == "b")
    { // beginning of else if
     
    // sets the color of the Queen to white
    q.setColor("Black");
     
    // boolean used in while loop to test for in-bounds coordinates
    boolean isValidCords23 = false;
     
    // tests for in-bounds coordinates.  Will keep asking for values till they are both
    // between 0 and 7.  
     
    while (isValidCords23 == false)
    { // beginning of while
     
    // boolean used in while loop with try/catch to check if x is an integer.
    boolean isValidX23 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (isValidX23 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Queen's position.");
     
    // user input for row for current position
     
    int x23 = console.nextInt();
    isValidX23 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // boolean used in while loop with try/catch to check if y is an integer.
    boolean IsValidY23 = false;
     
    // while loop that will keep asking the user for an integer till they enter an integer
     
    while (IsValidY23 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Queen's position.");
     
    // user input for column for current position
    int y23 = console.nextInt();
    IsValidY23 = true;
    } // end of try
     
    catch(InputMismatchException imeRef)
    { // beginning of catch
     
    // prints out message for Input Mismatch Exception
    System.out.println("Exception: " + imeRef.toString());
    } // end of catch
     
    } // end of while
     
    // checks to see if coordinates are in-bounds.  If they aren't
    // it sets isValidCords11 to false and so asks the user to enter the coordinates again
     
    if (x23 < 0 || x23 > 7 || y23 < 0 || y23 > 7)
    { // beginning of if
     
    // output telling user to enter values between 0 and 7
    System.out.println("Please enters values between 0 and 7.  Thank you.");
     
    // sets condition isValidCords7 to false so it'll ask user again till they enter
    // all in-bounds coordinates.  However, since the color is valid, isValidColor2 
    // will be set to true so it won't ask that again.
     
    isValidCords23 = false;
    isValidColor6 = true;
    } // end of if
     
    else
    { // beginning of else
     
    // makes a point with values x and y that are given by user
     
    Point pt23 = new Point(x23,y23);
     
    q.setPosition(pt23);
     
    // boolean used to check for try/catch block while loop for a valid int x55 value 
    // for new cord.
     
    // used to check if new cords are in-bounds
    boolean isValidCords24 = false;
     
    while (isValidCords24 == false)
    { // beginning of while 
     
    boolean isValidX24 = false;
     
    // will ask for an integer till the user enters an integer
    while (isValidX24 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter row for Queen's new position.");
     
    // user input for row for Queen's new position
    int x24 = console.nextInt();
     
    isValidX24 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    boolean IsValidY24 = false;
     
    // will ask for an integer till the user enters an integer
    while (IsValidY24 == false)
    { // beginning of while
     
    try{ // beginning of try
     
    System.out.println("Enter column for Queen's new position.");
     
    // user input for column for Queen's new position
    int y24 = console.nextInt();
     
    IsValidY24 = true;
    } // end of try
     
    catch (InputMismatchException imeRef)
    { // beginning of catch
     
    System.out.println("Exception: " + imeRef.toString());
     
    } // end of catch
     
    } // end of while
     
    // checks to see if new position is in-bounds
     
    if (x24 < 0 || x24 > 7 || y24 < 0 || y24 > 7)
    { // beginning of if
    System.out.println("Please enter values between 0 and 7.  Thank you.");
     
    // sets isValidCords8 to false, but isValidColor3 and isValidCords7 are true
    // so those two won't have to be asked for again.
     
    isValidCords24 = false;
    isValidCords23 = true;
    isValidColor6 = true;
    } // end of if 
     
    else
    { // beginning of else
     
    // makes a point for the coords of the new position
     
    Point pt24 = new Point(x24, y24);
     
    q.setNewPosition(pt24);
     
    System.out.println(q.toString());
     
    isValidCords24 = true;
    isValidCords23 = true;
    isValidColor6 = true;
    } // end of else
     
     
    } // end of while
     
    } // end of while
     
    } // end of else if
    }
     
    else
    { // beginning of else
    System.out.println("Enter a valid color.");
    isValidColor6 = false;
    } // end of else
     
    } // end of while
     
     
     
    } // end of else if
     
    // if the user exits
     
    else if (p == 'X' || p == 'x')
    { // beginning of else if
     
    System.exit(0);
     
    } // end of else if
     
     
    // if the user enters a char but not one of the ones on the menu 
    else
    System.out.println("Make a valid selection.");
     
    } // end of while
     
    } // end of main
    }

    I know it can't find the piece classes, as I haven't made them yet, but I do know that that's not what's causing the error.

    I'm missing a bracket somewhere I think, I just don't know where. Maybe I have too many brackets somewhere. Or likely both.

  11. #9
    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: Waddle the Java Jedi Penguin needs help with assignment.

    Why can't it find most of my x and y variables
    What is the "it"?
    Are you getting error messages?
    Please copy full text of error message and paste it here. Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^

    I'm missing a bracket somewhere
    Does your IDE have a matching {} finder? use that to pair up the { and }

  12. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (September 20th, 2010)

  13. #10
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    Quote Originally Posted by Norm View Post
    What is the "it"?
    Are you getting error messages?
    Please copy full text of error message and paste it here. Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^


    Does your IDE have a matching {} finder? use that to pair up the { and }
    Like

    x cannot be resolved
    y cannot be resolved

    Could be glitches in my try/catch blocks and their accompanying while loops.

  14. #11
    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: Waddle the Java Jedi Penguin needs help with assignment.

    You have 240+ posts. I would assume that you know about the "scope" of variable definitions. If not, you need to do some research on the topic.

  15. #12
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    I know it's losing scope. I just don't know why. Probably the try/catch blocks, but I thought I took care of that.

  16. #13
    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: Waddle the Java Jedi Penguin needs help with assignment.

    I just don't know why
    If you define a variable inside of { }s, when the execution exits the {}s, the variable goes out of scope and is GONE.

  17. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (September 20th, 2010)

  18. #14
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    oh, so I define the ints outside of it. If I do that, will it lose the values, even if the ints are defined outside, when it exits the
    {}? I actually thought it might be that, but I was wondering if it was a missing bracket and that doing that would only cause a ton of Null Pointer Exceptions.

  19. #15
    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: Waddle the Java Jedi Penguin needs help with assignment.

    I define the ints outside of
    Yes, you define the ints at the outer most level of {}s that you want the ints to be in scope.

  20. #16
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    For strings, if you have the user enter a value, can you say something like

    if (userInput == "C" || userInput == "c")

    or must you use the

    if (userInput.equals("C") || userInput.equals("c")

    ?

  21. #17
    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: Waddle the Java Jedi Penguin needs help with assignment.

    You should use the method to compare objects.

  22. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (September 20th, 2010)

  23. #18
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    Can you use a have a getMethod call a void setMethod and set a value in the get method to the called setMethod like this:

    setMethod()
    {

    }

    getMethod{

    dataType value = setMethod();

    return(value);

    }

    Also, can you have a defined getMethod call an abstract setMethod, of the same class, as long as all subclasses that call these methods define all the abstract methods?

  24. #19
    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: Waddle the Java Jedi Penguin needs help with assignment.

    Can you use a have a getMethod call a void setMethod
    dataType value = setMethod(); // this doesn't work because setMethod does not return anything. (void)

  25. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (September 20th, 2010)

  26. #20
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    Ok, so how do you do it then?

    I want to be able to set it and return it. Can I just combine them?

    That might be problematic as I call the setMethods and pass them parameters in the test program.

    If it weren't for the fact that the class is abstract, could I just call the setMethods in the constructor and have them be available that way?

  27. #21
    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: Waddle the Java Jedi Penguin needs help with assignment.

    Can I just combine them?
    Yes you can put any code you want in your methods.

  28. #22
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Waddle the Java Jedi Penguin needs help with assignment.

    Ok. Can I just call the setMethod? If I can, how do I get the value I set it to out of there so I can return it in the getMethod?

    It would be for the best if I had both get and set methods, instead of a single setMethod that did both. Well I pass it a parameter from the test program, it might just return a value. Also, if I call the set method again directly in the toString(), won't it set it again?

  29. #23
    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: Waddle the Java Jedi Penguin needs help with assignment.

    Are you asking a serious question, or just wondering about various coding techniques?

    Write a small simple program that compiles and executes to show what your problem is. Post it here.

  30. #24
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Question Re: Waddle the Java Jedi Penguin needs help with assignment.

    private String color;
     
    public void setColor (String color2)
    {
     
    String color3;
     
    if (color2.equals("White"))
    color3 = "White";
     
    else if (color2.equals("Black"))
    color3 = "Black";
    }
     
    public String getColor()
    {
     
    color = this.color3;
     
    return (color);
     
    }
    Last edited by javapenguin; September 20th, 2010 at 04:10 PM.

  31. #25
    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: Waddle the Java Jedi Penguin needs help with assignment.

    Why does the setColor method have all that logic? Don't bother to tell me. It must not be important if there are not any comments in the code describing why. color3 is a local variable and will go away when the code exits the method.

    Why does the getColor method change the contents of the color variable? Again don't bother explaining.
    get methods should NOT do anything other than get the value. "Side effects" can cause bugs that are hard to find in large programs.

  32. The Following User Says Thank You to Norm For This Useful Post:

    javapenguin (September 20th, 2010)

Page 1 of 2 12 LastLast

Similar Threads

  1. my java assignment -- please help
    By java_beginner in forum Java Theory & Questions
    Replies: 6
    Last Post: May 20th, 2010, 08:32 AM
  2. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  3. Beginner needs help with simple java assignment.
    By joachim89 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2010, 07:53 PM
  4. I need extensive help with my java assignment
    By MoshMoakes in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 12th, 2009, 07:44 PM
  5. [SOLVED] Problem with Grading calculator in java program
    By Peetah05 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: March 28th, 2009, 04:25 PM