Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Test Cases:
- AdvancedAstrologyTest verifyNoFields Ok
- AdvancedAstrologyTest testPrintStars Fail
- You didn't print any spaces when printStars was called.
- AdvancedAstrologyTest testPrintSpaces1 Ok
- AdvancedAstrologyTest testPrintSpaces2 Ok
- AdvancedAstrologyTest testPrintSmallTriangle Ok
- AdvancedAstrologyTest testPrintTriangle Ok
- AdvancedAstrologyTest testChristmasTree0 Ok
- AdvancedAstrologyTest testChristmasTree1 Ok
- AdvancedAstrologyTest testChristmasTree2 Ok
- Source Code:
- public class AdvancedAstrology {
- public static void printStars(int number) {
- // part 1 of the exercise
- int stars = 1;
- while (stars <= number) {
- System.out.print("*");
- stars++;
- }
- }
- public static void printSpaces(int number) {
- // part 1 of the exercise
- int spaces = 1;
- while (spaces <= number) {
- System.out.print(" ");
- spaces++;
- }
- }
- public static void printTriangle(int size) {
- // part 2 of the exercise
- for (int height = 1; height <= size; height++) {
- printSpaces(size - height);
- printStars(height);
- System.out.println("");
- }
- }
- public static void christmasTree(int height) {
- // part 3 of the exercise
- for (int size = 1; size <= height; size++) {
- printSpaces(height - size);
- if (size > 1) {
- printStars(size * 2 - 1);
- } else {
- printStars(size);
- }
- System.out.println("");
- }
- for (int trunk = 0; trunk < 2; trunk++) {
- printSpaces (height - 2);
- System.out.println("***");
- }
- }
- public static void main(String[] args) {
- // The tests are not checking the main, so you can modify it freely.
- printTriangle(5);
- System.out.println("---");
- christmasTree(4);
- System.out.println("---");
- christmasTree(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment