Guest User

Untitled

a guest
Mar 29th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.16 KB | None | 0 0
  1. import sun.awt.Symbol;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class coscos {
  7. public static void main(String[] args)
  8. {
  9. String Direction;
  10. char Character;
  11. int Height;
  12. Height = getHeight();
  13. Character = getCharacter();
  14. Direction = getDirection();
  15.  
  16. switch(Direction)
  17. {
  18. case "UP" :
  19. XmassTreeUp(Height, Character);
  20. break;
  21.  
  22. case "DOWN" :
  23. XmassTreeDown(Height, Character);
  24. break;
  25.  
  26. case "RIGHT" :
  27. XmassTreeRight(Height, Character);
  28. break;
  29.  
  30. case "LEFT" :
  31. XmassTreeLeft(Height, Character);
  32. break;
  33.  
  34. default:
  35. System.out.print("Wybrano niepoprawny kierunek.");
  36. break;
  37. }
  38.  
  39. }//Koniec Main
  40.  
  41. public static int getHeight(){
  42. int Wejsciowa = 0;
  43. System.out.print("Podaj Wysokosc choinki : ");
  44. for(;;) {
  45. Scanner HeightScanner = new Scanner(System.in);
  46. if(HeightScanner.hasNextInt()) {
  47. Wejsciowa = HeightScanner.nextInt();
  48. if(Wejsciowa > 0)
  49. return Wejsciowa;
  50. }//Koniec petli if
  51. else
  52. System.out.print("Podana wartosc musi byc liczba oraz wieksza od 0: ");
  53. }//Koniec Petli For
  54. }//Koniec klasy getHeight
  55.  
  56. public static char getCharacter(){
  57. char Znak =' ', defaultCharacter;
  58. String StringZnak = " ";
  59. System.out.print("Podaj pojedynczy znak (np.*) : ");
  60. Scanner scanCharacter = new Scanner(System.in);
  61. if(scanCharacter.hasNext()) {
  62. StringZnak = scanCharacter.nextLine();
  63. Znak = StringZnak.charAt(0);
  64. }//Koniec Petli if
  65. if(StringZnak.length() == 1)
  66. return Znak;
  67. else
  68. System.out.println("Podano znak dluzszy niz jeden znak. Uzycie domyslnego znaku.(*) ");
  69. return '*';
  70.  
  71. }//Koniec klasy getCharacter;
  72.  
  73.  
  74. public static String getDirection(){
  75. String kierunek;
  76. String Tempname;
  77. System.out.print("Podaj kierunek w którym ma być narysowana choinka (UP,DOWN,RIGHT,LEFT) : ");
  78. for(;;) {
  79.  
  80. Scanner DirectionScanner = new Scanner(System.in);
  81. kierunek = DirectionScanner.next();
  82. kierunek = kierunek.toUpperCase();
  83.  
  84. return kierunek;
  85.  
  86. }//Koniec petli for
  87. }//Koniec klasy getDirection
  88.  
  89. public static void XmassTreeUp(int Height, char Character) {
  90.  
  91. for(int DrawInt = 0;DrawInt< Height; DrawInt++){
  92. drawCharacter(true,Height -DrawInt - 1, ' ', false);
  93. drawCharacter(true,2 * DrawInt + 1, Character, true);
  94.  
  95. System.out.println();
  96. }//Koniec petli for
  97. }//Koniec XmassTreeUp
  98.  
  99. public static void XmassTreeDown(int Height, char Character) {
  100.  
  101. for(int DrawInt = 0 ;DrawInt < Height ;DrawInt++) {
  102. drawCharacter(true,1*DrawInt,' ', false);
  103. drawCharacter(true,2* Height - 2*DrawInt - 1, Character, false);
  104. System.out.println("");
  105. }//Koniec petli for
  106. }//Koniec XmassTreeDown
  107.  
  108. public static void XmassTreeRight(int Height, char Character) {
  109.  
  110. drawCharacterRUpLDown(true, Height, Character);
  111. drawCharacter(false, Height, Character, false);
  112. drawCharacterLUpRDown(true, Height, Character);
  113.  
  114. }//Koniec XmassTreeRight
  115.  
  116. public static void XmassTreeLeft(int Height, char Character) {
  117.  
  118. drawCharacterLUpRDown(false, Height, Character);
  119. drawCharacter(false, Height, Character, false);
  120. drawCharacterRUpLDown(false, Height, Character);
  121.  
  122. }//Koniec XmassTreeLeft
  123.  
  124. public static int RandomBubbles(int min, int max){
  125. int range = (max - min) + 1;
  126. return (int)(Math.random() * range) + min;
  127.  
  128. }//Koniec klasy RandomBubbles
  129.  
  130. public static void drawCharacter(boolean ifside ,int Height, char Character,boolean bubbles){
  131. for (int CharacterInt = 0; CharacterInt < Height; CharacterInt++){
  132. if(bubbles){
  133. if(RandomBubbles(1,10) % 4 == 0)
  134. System.out.print("o");
  135. else
  136. System.out.print(Character);
  137. }//Koniec petli if zew.
  138. else
  139. System.out.print(Character);
  140. }//Koniec petli for;
  141. if(!ifside)
  142. System.out.println("");
  143. }//Koniec funkcji drawCharacter
  144.  
  145. public static void drawCharacterLUpRDown(boolean side, int Height, char Character){
  146.  
  147. for(int SymbolInt = 0; SymbolInt < Height - 1; SymbolInt++){
  148. for(int SpaceInt = 0;SpaceInt < Height - SymbolInt - 1; SpaceInt++){
  149. if(!side)
  150. System.out.print(" ");
  151. else
  152. System.out.print(Character);
  153.  
  154. }//Koneic petli for wew.
  155.  
  156. for(int CharacterInt = 0; CharacterInt <= SymbolInt; CharacterInt++){
  157. if(!side)
  158. System.out.print(Character);
  159. else
  160. System.out.print(" ");
  161.  
  162. }//Koniec petli for wew.
  163.  
  164. System.out.println("");
  165.  
  166. }//Koniec petli for zew.
  167. }//Koniec klasy drawCharacterLUpRDown
  168.  
  169. public static void drawCharacterRUpLDown(boolean side, int Height, char Character){
  170.  
  171. for(int SymbolInt = Height -1; SymbolInt > 0; SymbolInt--){
  172. for(int LineInt = Height - SymbolInt; LineInt > 0; LineInt--){
  173. if(!side)
  174. System.out.print(" ");
  175. else
  176. System.out.print(Character);
  177. }//Koniec petli for wew.
  178.  
  179. for(int SpaceInt = 0; SpaceInt < SymbolInt; SpaceInt++) {
  180. if(!side)
  181. System.out.print(Character);
  182. else
  183. System.out.print(" ");
  184. }//Koniec Petli for wew.
  185.  
  186. System.out.println("");
  187.  
  188. }//Koniec petli for zew.
  189. }//Koniec klasy drawCharacterRUpLDown
  190.  
  191. }//Koniec Głównej Klasy
Advertisement
Add Comment
Please, Sign In to add comment