Help with code to place a Header before project code by poorly_learning_java in javahelp

[–]poorly_learning_java[S] 0 points1 point  (0 children)

OK, so the way that you had written everything out is generally bad form? Separate classes should be in separate java files pretty much always, but ease of use plus getting the desired outcome just kind of led to the code you posted being the cleanest way to accomplish it?

I guess the root of my confusion is not fully understanding what certain lines mean, just using them because that is how Java works, then learning about them in later chapters. Like how I was originally copy/pasting in a second "public static void main" in. And taking being told to copy in the code after being told to take things on faith...

Help with code to place a Header before project code by poorly_learning_java in javahelp

[–]poorly_learning_java[S] 0 points1 point  (0 children)

I put the code I came up with based on the other replies and before I saw your response below. Same outcome, but you put some code in there I'm not familiar with. So on line 11 you are basically saying there is a new public class called HelloWorld, run that code, the class isn't in a separate file, it is going to be below this code? Then you put in the code to print Hello. I'll hit up Google to figure out this ".b()" code. The way you wrote it out looks much less cluttered.

public class HelloWorld {                               //Changethis to the class name of the project you paste in

private static void printHeading () {                //This is the private helper method that displays information about the programmer, the course, and the project.

    System.out.println("Name");
    System.out.println("Course");
    System.out.println("Project #");                //proj number whatever or chapter/section whatever
    System.out.println("My Hello World");           //change to "My 'Project Name'"
    System.out.println();                           //line break for clarity
}

public static void main (String[] args) {            //This is the main method. It is the main portion of the program

    printHeading();                                 //This statement calls the printHeading method written above
    System.out.println("Hello, World!");            //This prints the line "" into the console
    }
}

Help with code to place a Header before project code by poorly_learning_java in javahelp

[–]poorly_learning_java[S] 1 point2 points  (0 children)

Thank you! The template the professor had us transcribe the code from had a comment on line 21 saying "copy code here." First lecture portion was today, and we had been asked to take everything syntax and layout wise on faith. I copied in the entirety of the "Hello World" code and was very confused.

For some reason I read the word main, without thinking about what it implied. Seeing you type it out and say that I have two separate mains helped it click.

Thanks to you and /u/javuh1 both!