diagram-system / DIAGRAM SYSTEM / src / app / DrawingApp.java
DrawingApp.java
Raw
package app;

import java.util.Random;

public class DrawingApp {
	public static String getRectangle(int maxRows, int maxCols, char symbol) {
		if (maxCols < 1 || maxRows < 1) {
			return null;
		} else {
			String symbolString = "";
			for (int i = 0; i < maxRows; i++) {
				for (int j = 0; j < maxCols; j++) {
					symbolString += symbol;
				}
				symbolString += "\n";
			}
			return symbolString.trim();
		}
	}

	public static String getFlag(int size, char color1, char color2, char color3) {

		if (size < 3) {
			return null;
		}

		String stringBuilder = "";

		for (int i = 1; i <= (size * 2); i++) {
			for (int j = 1; j <= (size * 5); j++) {
				if (i == 1 || i == (size * 2)) {
					if (j == 1)
						stringBuilder += "" + (color1);
					else
						stringBuilder += "" + (color2);
				} else if (i == size || i == (size + 1)) {
					if (j <= size)
						stringBuilder += "" + (color1);
					else
						stringBuilder += "" + (color2);
				} else {
					if (i <= size) {
						if (j <= i)
							stringBuilder += "" + (color1);
						else
							stringBuilder += "" + (color3);
					} else {
						if (j <= (size - (i % (size + 1))))
							stringBuilder += "" + (color1);
						else
							stringBuilder += "" + (color3);
					}
				}
			}
			stringBuilder += "" + ("\n");
		}
		return stringBuilder.toString().trim();
	}

	public static String getHorizontalBars(int maxRows, int maxCols, int bars, char color1, char color2, char color3) {

		int number_of_Rows = maxRows / bars;

		String output = "";

		for (int j = 0; j < bars; j++) {
			for (int i = 0; i < number_of_Rows; i++) {
				for (int t = 0; t < maxCols; t++) {
					if (j % 3 == 0) {
						output += color1;
					} else if (j % 3 == 1) {
						output += color2;
					} else {
						output += color3;
					}
				}
				output += "\n";
			}
		}
		return output.trim();
	}

	public static String getVerticalBars(int maxRows, int maxCols, int bars, char color1, char color2, char color3) {

		String output = "";
		int verticalBarWidth = maxCols / bars;

		char colour = ' ';

		if (verticalBarWidth < 1) {
			return null;
		}

		for (int i = 0; i < maxRows; i++) {
			int columnCreator = -1, cols = verticalBarWidth * bars;
			for (int j = 0; j < cols; j++) {
				if (j % verticalBarWidth == 0) {
					columnCreator = (columnCreator + 1) % 3;
					if (columnCreator == 0) {
						colour = color1;
					} else if (columnCreator == 1) {
						colour = color2;
					} else {
						colour = color3;
					}
				}
				output += colour;
			}

			output += '\n';
		}

		return output.trim();
	}

	public static char getRandomColor(Random random) {

		int random_integer = random.nextInt(6);

		if (random_integer == 0) {
			return 'R';
		} else if (random_integer == 1) {
			return 'G';
		} else if (random_integer == 2) {
			return 'B';
		} else if (random_integer == 3) {
			return 'Y';
		} else if (random_integer == 4) {
			return '*';
		} else {
			return '.';
		}

	}

	private static boolean isValidColor(char color) {
		if (color == 'R' || color == 'G' || color == 'Y' || color == '*' || color == '.') {
			return true;
		} else
			return false;
	}
}