#Code works as expected but not being accepted to my mooc course any ideas?

1 messages · Page 1 of 1 (latest)

lean questBOT
#

<@&987246399047479336> please have a look, thanks.

lean questBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

twin sage
#

could u share the current output?

rocky cove
#

sure

#

cd C:\Users\16319\Documents\NetBeansProjects\mooc-java-programming-i\part02-Part02_34.AdvancedAstrology; JAVA_HOME=C:\\Users\\16319\\Desktop\\jdk-11.0.18+10 cmd /c "\"C:\\Program Files\\TMCBeans\\java\\maven\\bin\\mvn.cmd\" -Dexec.args=\"-classpath %classpath AdvancedAstrology\" -Dexec.executable=C:\\Users\\16319\\Desktop\\jdk-11.0.18+10\\bin\\java.exe -Dfile.encoding=UTF-8 -T=1 -q process-classes org.codehaus.mojo:exec-maven-plugin:1.5.0:exec"
   *
  **
 ***
****
---
     

   *
  ***
 *****
*******
  ***
  ***
---
           

         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
        ***
        ***
        ***
lean questBOT
# rocky cove ```java cd C:\Users\16319\Documents\NetBeansProjects\mooc-java-programming-i\pa...

Detected code, here are some useful tools:

Formatted code
cd C : \Users\16319\Documents\NetBeansProjects\mooc - java - programming - i\part02 - Part02_34.AdvancedAstrology;
JAVA_HOME = C : \\Users\\16319\\Desktop\\jdk - 11.0.18 + 10cmd / c"\"C:\\Program Files\\TMCBeans\\java\\maven\\bin\\mvn.cmd\" -Dexec.args=\"-classpath %classpath AdvancedAstrology\" -Dexec.executable=C:\\Users\\16319\\Desktop\\jdk-11.0.18+10\\bin\\java.exe -Dfile.encoding=UTF-8 -T=1 -q process-classes org.codehaus.mojo:exec-maven-plugin:1.5.0:exec" *  *  *  *  *  *  *  *  *  * -- -  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  * -- -  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
rocky cove
#
cd C:\Users\16319\Documents\NetBeansProjects\mooc-java-programming-i\part02-Part02_34.AdvancedAstrology; JAVA_HOME=C:\\Users\\16319\\Desktop\\jdk-11.0.18+10 cmd /c "\"C:\\Program Files\\TMCBeans\\java\\maven\\bin\\mvn.cmd\" -Dexec.args=\"-classpath %classpath AdvancedAstrology\" -Dexec.executable=C:\\Users\\16319\\Desktop\\jdk-11.0.18+10\\bin\\java.exe -Dfile.encoding=UTF-8 -T=1 -q process-classes org.codehaus.mojo:exec-maven-plugin:1.5.0:exec"
   *
  **
 ***
****
---
     

   *
  ***
 *****
*******
  ***
  ***
---
           

         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
        ***
        ***
        ***
#

the first tree is correct but the second tree has an unexpected third line at the base

#

also is coding always this confusing with like spaces and math lol i feel like everything before this came pretty simple then bam this exercise

twin sage
#

those exercises are to practice loops and get a better understanding of which part in ur loops controls what

rocky cove
#

gotcha cause im pretty sure just getting confused with the math portion of it

#

something is just slightly off

twin sage
#

yeah don't worry. it's all just practice. we all struggled with those things until we did it a few times

#

i didnt quite understand which part of the output is wrong. the output u shared only has two rows for the second tree base?

rocky cove
#

well if i remove the = in for (int i = 0; i <= height / 4; i++) { it gives me the correct amount in the second tree and the wrong amount in the first tree

#

the output is supposed to look like this

For example, the call christmasTree(4) should print the following:

Sample output

   *
  **
 ***
****

   *
  ***
 *****
*******
  ***
  ***
The call christmasTree(10) should print:

Sample output

         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
        ***
        ***

but im getting

   *
  **
 ***
****
---
     

   *
  ***
 *****
*******
  ***
---
           

         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
        ***
        ***
twin sage
#

so now ur missing a line in the base of the second tree?

rocky cove
#

well i just added the = back

#

just not sure where im going wrong here

twin sage
#

ah wait. i thought ur showing 3 trees, but its 2 trees

rocky cove
#

sorry

#

this is the output im getting

#
   *
  **
 ***
****
---
     

   *
  ***
 *****
*******
  ***
  ***
---
           

         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
        ***
        ***
        ***
twin sage
#

can u show the task? maybe they want / 3 and not / 4 or other stuff?

rocky cove
#
Define a method called christmasTree(int height) that prints the correct Christmas tree. The Christmas tree consists of a triangle with the specified height as well as the base. The base is two stars high and three stars wide, and is placed at the center of the triangle's bottom. The tree is to be constructed by using the methods printSpaces and printStars.

For example, the call christmasTree(4) should print the following:

Sample output

   *
  ***
 *****
*******
  ***
  ***
The call christmasTree(10) should print:

Sample output

         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
        ***
        ***
twin sage
#

it seems the base of always supposed to be 2 rows only

#

so u don't need any math

#

nothing based on height. just always 2

rocky cove
#

yeah

twin sage
#

so just create a loop that makes two rows. nothing dynamic

#

u kinda overcomplicated it

#

by making some math depending on the height

rocky cove
#

so just take out the height / 4?

twin sage
#

but literally just put 2 there instead

rocky cove
#

got it!

#

i did this

#

public class AdvancedAstrology {

    //Creates a method to print stars
    public static void printStars(int number) {
        for (int i = 0; i < number; i++) {
            System.out.print("*");
        }
        System.out.println();
    }

    //Creates a method to print spaces
    public static void printSpaces(int number) {
        for (int i = 0; i < number; i++) {
            System.out.print(" ");
        }
    }

    //Creates a method to create a triangle
    public static void printTriangle(int size) {
        for (int i = 1; i <= size; i++) {
            int spaces = size - i;
            printSpaces(spaces);
            printStars(i);
        }
    }

    //Creates a method that makes a cristmas tree
    public static void christmasTree(int height) {
        for (int i = 0; i <= height; i++) {
            int spaces = height - i;
            printSpaces(spaces);
            if (i == 0) {
                System.out.println(" ");
            }
            printStars(2 * i - 1);
        }
        for (int i = 0; i <= 1; i++) {
            printSpaces(height - 2);
            printStars(3);
        }
    }

    //Main code
    public static void main(String[] args) {

        //Prints Triangle, Christmas tree and big tree
        printTriangle(4);
        System.out.println("---");
        christmasTree(4);
        System.out.println("---");
        christmasTree(10);
    }
}
twin sage
#

works now? looks good

rocky cove
#

oh wait

#

im still failing somehow

twin sage
#

but one problem less cat_thumbs_up

rocky cove
#

yeah lol

#

idk why its giving the expected output i think

twin sage
#

maybe u have a trailing newline somewhere?

rocky cove
#
When calling christmasTree(4) is called, the first line should contain 3 spaces and then one star, make sure there's not too much or too little spaces
twin sage
#

like posting an empty line too much at the end

rocky cove
#

fixed it

#

changed int i = 1 in the top part and it passed

#

damn that took me forever thank you for the guidence ❤️