Hey again rhymin,
Can anyone help with this?
I'm not quite sure, but did you receive my personal message (PM) in regards to why I may take long when replying to your post?
This is what I have so far and it only displays a message about the salesperson earning a fixed monthly salary of $4,000. I'm really not sure how to create another class in addition to the controlling class. I didn't want to go any further in case I'm wrong already.
package commissioncalculation1;
Adding another class is simple... In NetBeans in your "
Project Explorer" (Normally top-left hand corner, select the "
Projects" tab).
> Then right click on "
Source Packages" or the desired package name
> Select "
New"
> And then click "
Java Class..."
Change the name of the class to a name that will describe the functions that will reside inside that class (Eg. CommisionCalculator). In your case, the main class resides in the "commissioncalculation1" package and I would recommend putting your additional class in the same package (I will explain packages later on). After you have done this click "
Finish". You will notice that you have a new class in your "
Project Explorer" and it should also open the code window for that particular class so you can get coding.
By the way, when I copied and pasted the code, the indentations didn't copy correctly. But, I know that part is at least right from the way it looks in the IDE.
Make sure when posting code, you paste your code between the "<code->" tags like you did in your next posts.
Also, I'm not sure why this line popped up: package commissioncalculation1;
All I did was create new project and selected java application from the java category. I've never seen that before.
Usually when you create a class is it good practice to put it into a package. You should be able to place the class in a "
Default Package" (In other words not in a package at all) but your IDE might warn you. So maybe in your case you were giving the option to place it in a auto-named package from your IDE, hence the package line that popped up. That first line "
package commissioncalculation1" just specifies which package (ie. Folder) your class resides in. Packages are useful because you can categorize your code into packages and partition each classes functionality according to the type of functionality the hold... In this case, I mentioned that I would recommend you putting both classes in the same package; The reason for this is, if you do not you will have to use the "
import" keyword to be able to use the functionality of your other class. This is a really brief explanation of packages, I would recommend reading up more here so you can get a broader understanding:
http://en.wikipedia....ki/Java_package (Packages as stated there are important for
namespacing [Research this term])
How do I make this into 2 classes? I have no idea what should be included in 1 class or the other. I know you said one class will consist of the main function where the code is executed and the 2nd contains the functions, but I'm still confused.
Is there a way I will know precisely what to put in each class?
Follow the instructions above in order to create your 2nd class. In this case you have mentioned not having any idea of which functions should be in what classes, so for the purpose of your first assignment my tip to you would be to have only
one function in your main class (This being the
static void main() function) and all other functions you have written be placed in the second class you have created. Maybe doing this will make you understand the reasoning for separating classes. Remember classes encapsulate their own functionality relating to the class, so its just a method of making code alot more neater as well as
reusable. A nice way of thinking of what functions should go into a particular class is to think of it like this: Keep in mind that you are creating a class that contains functionality that some other developer will be making use of, that other developer is not concerned with how your class and functions work, he just wants to be able to "call" them and use them without understanding its underlying method (Great example is when you calling the output stream writer to write output to the screen, you are not aware of how the underlying functionality works, but you happy knowing that it works. That output stream writer also resides in its own class, and when you call the println() function you are just calling that function that is within its own class).
Hopefully that description will help you in understand more in "precisely" what to put into each class for now and your future assignments. Try work on that to complete you assignment tasks and post back when you are done or if you are having problems. Just note when replying to this thread try and keep is neat and try rather put your posts into one post instead of posting multiple times, please also be patient with the responding reply as we cannot be on the forums all the time but I will make a conscious effort of getting back to you as soon as possible.
Peace Out