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
}