Guest User

Untitled

a guest
Oct 12th, 2026
26
0
27 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. Test Cases:
  2.  
  3. AdvancedAstrologyTest verifyNoFields Ok
  4.  
  5. AdvancedAstrologyTest testPrintStars Fail
  6.  
  7. You didn't print any spaces when printStars was called.
  8.  
  9. AdvancedAstrologyTest testPrintSpaces1 Ok
  10.  
  11. AdvancedAstrologyTest testPrintSpaces2 Ok
  12.  
  13. AdvancedAstrologyTest testPrintSmallTriangle Ok
  14.  
  15. AdvancedAstrologyTest testPrintTriangle Ok
  16.  
  17. AdvancedAstrologyTest testChristmasTree0 Ok
  18.  
  19. AdvancedAstrologyTest testChristmasTree1 Ok
  20.  
  21. AdvancedAstrologyTest testChristmasTree2 Ok
  22.  
  23.  
  24. Source Code:
  25.  
  26. public class AdvancedAstrology {
  27.  
  28. public static void printStars(int number) {
  29. // part 1 of the exercise
  30. int stars = 1;
  31. while (stars <= number) {
  32. System.out.print("*");
  33. stars++;
  34. }
  35. }
  36.  
  37. public static void printSpaces(int number) {
  38. // part 1 of the exercise
  39. int spaces = 1;
  40. while (spaces <= number) {
  41. System.out.print(" ");
  42. spaces++;
  43. }
  44. }
  45.  
  46. public static void printTriangle(int size) {
  47. // part 2 of the exercise
  48. for (int height = 1; height <= size; height++) {
  49. printSpaces(size - height);
  50. printStars(height);
  51. System.out.println("");
  52. }
  53.  
  54. }
  55.  
  56. public static void christmasTree(int height) {
  57. // part 3 of the exercise
  58. for (int size = 1; size <= height; size++) {
  59. printSpaces(height - size);
  60. if (size > 1) {
  61. printStars(size * 2 - 1);
  62. } else {
  63. printStars(size);
  64. }
  65. System.out.println("");
  66. }
  67.  
  68. for (int trunk = 0; trunk < 2; trunk++) {
  69. printSpaces (height - 2);
  70. System.out.println("***");
  71. }
  72. }
  73.  
  74. public static void main(String[] args) {
  75. // The tests are not checking the main, so you can modify it freely.
  76.  
  77. printTriangle(5);
  78. System.out.println("---");
  79. christmasTree(4);
  80. System.out.println("---");
  81. christmasTree(10);
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment