r/learnjava • u/[deleted] • Sep 25 '23
Wtf is this BS. Mooc Java Part 1 Advanced Astrology Spoiler
public class AdvancedAstrology {
public static void printStars(int number) {
// part 1 of the exercise
for(int i = 0; i < number; i++){
System.out.print("*");
}
}
public static void printSpaces(int number) {
// part 1 of the exercise
for(int i = 0; i < number; i++){
System.out.print(" ");
}
}
public static void printTriangle(int size) {
// part 2 of the exercise
for(int i = 1; i <= size; i++){
printSpaces(size - i);
printStars(i);
System.out.println("");
}
}
public static void christmasTree(int height) {
// part 3 of the exercise
int starNumber = 1;
for(int i = 1; i <= height; i++){
printSpaces(height - i);
printStars(starNumber);
printSpaces(height - i);
System.out.println("");
starNumber += 2;
}
for(int i = 0; i < 2; i ++){
printSpaces(height - 2);
printStars(3);
System.out.println("");
}
}
public static void main(String[] args) {
// The tests are not checking the main, so you can modify it freely.
printTriangle(4);
System.out.println("---");
christmasTree(4);
System.out.println("---");
christmasTree(10);
}
}This is my code for this exercise, it works just as it should, christmas tree and all, but since it's not written exactly like the page expects, the tests do not pass and therefore i don't get the points. Seriously, what is this fucking bullshit?
22
u/desrtfx Sep 25 '23 edited Sep 25 '23
This is teaching you to adhere to specifications.
Another important lesson.
Automated tests in professional programming will do the same.
Side note: you are printing extra spaces right of the tree - and that is the problem. You do not need them.
0
Sep 25 '23
Side note: you are printing extra spaces right of the tree - and that is the problem. You do not need them.
Yeah thanks I figured it out, i was tired and frustrated as hell yesterday lol. I guess it's part of this shit. I like it
1
u/Automatic-Coffee-740 Sep 28 '23
Don't even waste time thinking about it..years from now you'll be whizzing through your work thinking.."gees is that what it was"....just part of the learning process. The real work is way more engaging. Keep it up.
14
u/hugthemachines Sep 25 '23
Maybe you thought the test worked like this: "Well, as long as it's pretty close to what we expect, we let it pass". Instead many tests work like this: "the text should be exactly to the letter as we expect and then we let it pass".
You learned something about tests.
2
Sep 25 '23
Yup. I'm learning something new everyday.
1
u/andrewbauxier Sep 26 '23
Don't feel bad, man, I'm learning too, and little stuff like this trips me up as well. Computers aren't human, though, and a 99% is not 100%. Bosses don't accept 99% either, nor will clients. Keep at it, buddy!
4
Sep 25 '23
You don't have to put spaces after every row of stars in the tree. I was stuck for a while at this too...
1
-3
u/wisdom_power_courage Sep 25 '23
That was the exercise that made me go "yeah I'm not doing these anymore I got the concept" lmao
2
-2
u/TheVasa999 Sep 25 '23
Exactly, this and the arrows and stuff. I got so mad at it not working or not taking my solution that i skipped it
•
u/AutoModerator Sep 25 '23
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full - best also formatted as code block
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.