Advertisement
GamesForCharity

holy SHIT dude

Dec 10th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. /**
  2. * Draws shapes with user-defined characters and lengths.
  3. *
  4. * @author Marcus Marchetti
  5. * @version Version 9001, 12/11/15
  6. */
  7. public class ShapeDrawer {
  8. /**
  9. * The character being used in the shapes.
  10. */
  11. private char character;
  12. /**
  13. * Creates a new ShapeDrawer with a default chatacter of "*".
  14. */
  15. public ShapeDrawer() {
  16. character = '*';
  17. }
  18. /**
  19. * Gets the current character being used.
  20. *
  21. * @return character The character being used.
  22. */
  23. public char getCharacter() {
  24. return character;
  25. }
  26. /**
  27. * Sets a new character to be used.
  28. *
  29. * @param newCharacter The new character to be used.
  30. */
  31. public void setCharacter(char newCharacter) {
  32. character = newCharacter;
  33. }
  34. /**
  35. * Creates a left lower right triangle.
  36. *
  37. * @param length The length of the triangle.
  38. */
  39. public void leftLowerTriangle(int length) {
  40. if (length < 1) {
  41. throw new IllegalArgumentException("Length cannot be less than 1!");
  42. } else {
  43. for (int i = 1; i <= length; i++) {
  44. for (int j = 0; j < i; j++) {
  45. System.out.print(character);
  46. }
  47. System.out.println("");
  48. }
  49. }
  50. }
  51. /**
  52. * Creates a left upper right triangle.
  53. *
  54. * @param length The length of the triangle.
  55. */
  56. public void leftUpperTriangle(int length) {
  57. if (length < 1) {
  58. throw new IllegalArgumentException("Length cannot be less than 1!");
  59. } else {
  60. for (int j = length; j > 0; j--) {
  61. for (int i = 0; i < j; i++) {
  62. System.out.print(character);
  63. }
  64. System.out.println("");
  65. }
  66. }
  67. }
  68. /**
  69. * Creates a right lower right triangle.
  70. *
  71. * @param length The length of the triangle.
  72. */
  73. public void rightLowerTriangle(int length) {
  74. if (length < 1) {
  75. throw new IllegalArgumentException("Length cannot be less than 1!");
  76. } else {
  77. for (int i = 0; i < length; i++) {
  78. for (int j = 2; j <= length - i; j++) {
  79. System.out.print(" ");
  80. }
  81. for (int k = 0; k <= i; k++) {
  82. System.out.print(character);
  83. }
  84. System.out.println("");
  85. }
  86. }
  87. }
  88. /**
  89. * Creates a right upper right triangle.
  90. *
  91. * @param length The length of the triangle.
  92. */
  93. public void rightUpperTriangle(int length) {
  94. if (length < 1) {
  95. throw new IllegalArgumentException("Length cannot be less than 1!");
  96. } else {
  97. int placeHolder = 0;
  98. for (int i = length; i >= 1; i--) {
  99. placeHolder++;
  100. for (int j = 1; j <= i; j++) {
  101. System.out.print(character);
  102. }
  103. System.out.println("");
  104. for (int k = 1; k <= placeHolder; k++) {
  105. System.out.print(" ");
  106. }
  107. }
  108. }
  109. }
  110. /**
  111. * Creates a diamond shape.
  112. *
  113. * @param length The length of the diamond.
  114. */
  115. public void diamond(int length) {
  116. if (length < 1 || (length % 2) == 0) {
  117. throw new IllegalArgumentException("Length cannot be less than one or an even number!");
  118. } else {
  119. int size = length;
  120. for (int i = 1; i < size; i += 2) {
  121. for (int k = size; k >= i; k -= 2) {
  122. System.out.print(" ");
  123. }
  124. for (int j = 1; j <= i; j++) {
  125. System.out.print(character);
  126. }
  127. System.out.println("");
  128. }
  129. for (int i = 1; i <= size; i += 2) {
  130. for (int k = 1; k <= i; k += 2) {
  131. System.out.print(" ");
  132. }
  133. for (int j = size; j >= i; j--) {
  134. System.out.print(character);
  135. }
  136. System.out.println("");
  137. }
  138. }
  139. }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement