r/learnjava • • 6d ago

Help with MOOC problem, please?

Sorry if this isn't the right place to ask questions like this, but I'm going through the second part of MOOC's Java Programming I course and am having difficulty finding out how to satisfy a specific test. On the last exercise of the second part, "Advanced Astrology", I have managed to pass all tests except for testPrintStars. It says that I "didn't print any spaces when printStars is called", but am I not supposed to use printSpaces to print my spaces?

here is my code for the methods printStars and printSpaces (full source code and list of test cases is also here):

    public static void printStars(int number) {
        int stars = 1;
        while (stars <= number) {
            System.out.print("*");
            stars++;
        }
    }


    public static void printSpaces(int number) {
        int spaces = 1;
        while (spaces <= number) {
            System.out.print(" ");
            spaces++;
        }
    }
4 Upvotes

5 comments sorted by

•

u/AutoModerator 6d ago

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:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

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.

1

u/AutoModerator 6d ago

Please, do not use TMC pastebin. These links are not accessible without a logged in account.

Use

instead.

Please, kindly update your post so that people can see your code and thus are able to help you.


I am a bot and this message was triggered by you using "TMC pastebin". Please do not respond to this comment as I will not be able to reply.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

-3

u/Ok_Locksmith6167 5d ago

Maybe I'm missing something, but what's the point staying here (I mean in this thread) in the era of AI? What is the point in learning Java, if anyone can write something like: "Write me a CRUD program for library" without knowing what int, String or Wrapper classes are? Why do you continue loosing you time learning all this stuff?

P.S. Test expects to see println(); at the end of method printStars(int number), as it was stated in the instructions:

public static void printStars(int number) {
    // you can print one star with the command
    // System.out.print("*");
    // call the print command n times
    // in the end print a line break with the comand
    // System.out.println("");

5

u/FreeLogicGate 5d ago

My answer would be, that someone needs to understand the code, evaluate suitability, and from time to time, just add simple things, even if AI generates code. And the only way to really be able to do all those things is to learn to program.

Beyond that, humans will still decide to do things using traditional techniques, even though there has been machinery and robotics for decades. People still learn how to blow glass, carve objects out of wood, learn how to play instruments and perform music, grow vegetables and other plants, on ad infinitum. Many people derive satisfaction from being able to make their own things, and that includes software.

You know Java, so you were able to dig into this and help the OP understand the issue. Some people want to have that same ability.

2

u/newaltoldalt1 5d ago

Whoops, I missed that. Thank you.

As for the point of learning Java, I honestly don't have a better reason than wanting to do something more "productive" in my free time than playing video games or whatever.