#Code works as expected but not being accepted to my mooc course any ideas?
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
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.
could u share the current output?
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"
*
**
***
****
---
*
***
*****
*******
***
***
---
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
***
***
***
Detected code, here are some useful tools:
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" * * * * * * * * * * -- - * * * * * * * * * * * * * * * * * * * * * * -- - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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
those exercises are to practice loops and get a better understanding of which part in ur loops controls what
gotcha cause im pretty sure just getting confused with the math portion of it
something is just slightly off
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?
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
*
**
***
****
---
*
***
*****
*******
***
---
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
***
***
so now ur missing a line in the base of the second tree?
ah wait. i thought ur showing 3 trees, but its 2 trees
sorry
this is the output im getting
*
**
***
****
---
*
***
*****
*******
***
***
---
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
***
***
***
can u show the task? maybe they want / 3 and not / 4 or other stuff?
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
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
***
***
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
yeah
so just create a loop that makes two rows. nothing dynamic
u kinda overcomplicated it
by making some math depending on the height
so just take out the height / 4?
but literally just put 2 there instead
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);
}
}
works now? looks good
but one problem less 
maybe u have a trailing newline somewhere?
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
like posting an empty line too much at the end