-1

Definitely not looking for anyone to do my homework, just having a little trouble understanding naming conventions in Eclipse as well as bracket placement.

I'm still getting pretty tripped up by not knowing exactly what to name my (not sure what the correct word is here) main class, the class I originally create in Eclipse after I create a Java Project and create a Package inside of my Java Project and then right-click my Package and select New/Class. Here is a link to the code and instructions the professor gave me by the way.

Right now I'm calling my "main class" Container in my Java Project/Package. I named it that because it was the first class declared in the code I have. Is this a bad idea, should I name it something else?

Also, is there anyone that can help me understand bracket placement a little better? I understand that brackets section off sections of code and that you can layer and nest sections of code within other code using brackets. What I don't get (for this current assignment especially) is how should I be nesting code inside other code using the brackets.

For instance, in the link I provided above my professor has structured the brackets so that the abstract class 'Container', as well as all the classes that extend 'Container' are completely cut-off and independent from each other as well as the rest of the code. The only part of the code which shares brackets with another is the class 'ContainerCollection' which nests the Main Method inside of it.

On all of my other assignments my code was structured so that I had a class declared at the top of my program which contained in its brackets all of the other classes, constructor, and methods including my Main Method. Here's an example of what I'm used to seeing, structurally speaking.

Anyway, I feel like I'm missing something fundamental about how these brackets section off and nest code. For instance, I didn't think that you could have sections independent of all other sections in the code, I thought everything had to be within the brackets of the main class. I would really appreciate any insight into this at all.

TylerH
  • 20,799
  • 66
  • 75
  • 101
antalt
  • 1
  • 3

1 Answers1

-1

Hi hi and welcome to programming :) It seems to me you have some problems understanding some fundamental stuff in coding itself. I'll try and answer some of the questions that you have outlined here (without getting too deep into the technicalities) as well as give an overview of some of the code that you've linked.

1) Naming your "Main" class.
The name of your 'main' class doesn't need to be anything special. Usually the class that holds the critical "main" method (that is, the public static void main(String[] args) { ... }) is just the class that "runs" your program. When I was doing assignments I often just named it CalculatorRunner.java or GameRunner.java or whatever.

2) Constructors, Classes, Methods, Brackets
From what I see in your questions, it seems like you also have a little trouble discerning the difference between Classes, Constructors, Methods. Do a little research and you'll learn to spot the subtle difference between the syntax and bracketing. :)

The code that your professor linked The code that your professor linked is set out somewhat poorly. Several classes are defined in the single text file which can be confusing for a new programmer. "OMG WHY ARE THERE SO MANY CLASSES IN HERE?! WHAT'S GOING ON?!" LOL don't panic. It's probably because your professor's lazy and doesn't want to separate the classes out. It's acceptable to the Java VM but not so fun for a programmer. Spot where the classes are and put them into their own class files and things will be much clearer. The Fantasy football code is much clearer and doesn't have multiple classes embedded in one.

Anyways, the questions you've asked is pretty textbook... practice a bit more and it'll all slowly come together. Hope it helps.

blaytenshi
  • 312
  • 3
  • 11