package ru.job4j.loop;

/**
 * Class Board.
 * @author Artem Khizhniakov (mailto:artem_khizhniakov@mail.ru).
 * @version $Id$.
 * @since 25.09.2017.
 */
public class Board {

    /**
     * Method draws a chessboard from the symbols x and spaces.
     * @param width .
     * @param height .
     * @return chess board from symbols x and spaces.
     */
    public String paint(int width, int height) {
       StringBuilder stringBuilder = new StringBuilder();
        for (int h = 1; h <= height; h++) {
            for (int w = 1; w <= width; w++) {
                if (h % 2 != 0) {
                    if (w % 2 != 0) {
                        stringBuilder.append("x");
                    } else {
                        stringBuilder.append(" ");
                    }
                } else {
                    if (w % 2 != 0) {
                        stringBuilder.append(" ");
                    } else {
                        stringBuilder.append("x");
                    }
                }
            }
            stringBuilder.append(System.getProperty("line.separator"));
        }
        return stringBuilder.toString();
    }
}
