Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Java Assignment Question


  • Please log in to reply

#1
rhymin

rhymin

    Member

  • Member
  • PipPipPip
  • 210 posts
I have an assignment for class. I am a going for a degree in networking, but for some reason they require us to take a Java programming class and they really let you have it. This is only the 2nd week and we are supposed to write, what seems like, a difficult program. I'm sure to the more experienced programmer that this isn't a big deal at all and is actually quite simple. But, even after reading all the material for the week (which ended up being close to 100 pages) and watching tutorial videos, I feel that I am even more lost. I was wondering if anyone could help me at all with this, and it would be GREATLY appreciated.

Write a Java application using NetBeans Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson. Consider the following factors:

  • A salesperson will earn a fixed monthly salary of $4,000.00.
  • A salesperson will also receive a commission as a sales incentive. Commission is a percentage of the salesperson’s annual sales. The current commission is 20% of total sales.
  • The total annual compensation is the fixed salary plus the commission earned.

The Java application should meet these technical requirements:

  • The application should have at least one class, in addition to the application’s controlling class (a controlling class is where the main function resides).
  • There should be proper documentation is the source code.
  • The application should ask the user to enter annual sales, and it should display the total annual compensation.

  • 0

Advertisements


#2
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,354 posts

I have an assignment for class. I am a going for a degree in networking, but for some reason they require us to take a Java programming class and they really let you have it. This is only the 2nd week and we are supposed to write, what seems like, a difficult program. I'm sure to the more experienced programmer that this isn't a big deal at all and is actually quite simple. But, even after reading all the material for the week (which ended up being close to 100 pages) and watching tutorial videos, I feel that I am even more lost. I was wondering if anyone could help me at all with this, and it would be GREATLY appreciated.

Write a Java application using NetBeans Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson. Consider the following factors:

  • A salesperson will earn a fixed monthly salary of $4,000.00.
  • A salesperson will also receive a commission as a sales incentive. Commission is a percentage of the salesperson's annual sales. The current commission is 20% of total sales.
  • The total annual compensation is the fixed salary plus the commission earned.

The Java application should meet these technical requirements:

  • The application should have at least one class, in addition to the application's controlling class (a controlling class is where the main function resides).
  • There should be proper documentation is the source code.
  • The application should ask the user to enter annual sales, and it should display the total annual compensation.

Hey there rhymin,

I think the reason for them requiring you to take Java Programming as part of your networking course is because once you've passed the basics of the language you will find Java is a great platform for learning concepts of networking. They will probably set you out into creating your own networking protocols (TCP, UDP, ect...) and is just a great language to fully understand exactly how certain protocols function. Instead of just knowing the theory behind how these vital protocols function, you will be able to practically apply them helping you to get the bigger picture of networking.

As for you making the time for reading material and tutorial videos, I have to say keep it up! Posted Image You can only learn more... Although I must add caution to your method by making you aware to grasp the fundamentals of the language first before going ahead into aspects that may seem daunting and intimidating. I assure you that once you start becoming more comfortable and confident with the language you will find that it is enjoyable and quite easy to work with to solve complex problems.

Ok, onto your task... It seems from the question you have given that it explicitly mentions "using NetBeans". NetBeans is a great IDE and there is nothing wrong with it! I had used NetBeans for a short period before moving to Eclipse and found Eclipse more comfortable to work in along with it having alot more options for plugins (Android SDK Posted Image). I would recommend just finding out if your institution will allow you to use another IDE other than NetBeans; Although in the case you cannot, NetBeans is absolutely fine and works just as-well, at the end of the day its about which ever one you feel more comfortable working in.

This assignment you have been given is a nice assignment to get you started off with and rather than any of the community members writing the code for you I would strongly suggest that you go ahead and first try it for yourself! It is extremely important that you grasp the basics of the Java language as you may find yourself lost further on into your course if you cannot progress from this point. So rather than just posting up code that you may or may not understand I will possibly help you understand the questions given to your more clearly (In my understand of them) which in-turn will make your task an easier one.

1. "The application should have at least one class, in addition to the application's controlling class (a controlling class is where the main function resides)." : This requirement basically means that you will require one more other class along with your main class. Your main class will consist of the "main()" function where all code is executed first when you compile and run your project. The second class will be one that contains the functions required to complete your tasks. In other words any task function code you "call" within your main class will reside in your second class...

2. "There should be proper documentation is the source code." : If I am correct, I believe the grammar in this requirement is incorrect as it should be "There should be proper documentation in the source code", what this requirement asks of you is to write what is known as JavaDocs for each of your functions. Here is a link (http://en.wikipedia.org/wiki/Javadoc) to get your started and is more than enough for what you require, I would recommend Googling Javadoc if you would like to learn more. But basically all Javadoc is, is an automated tool within Java that will generate documentation for each of your functions (Given that you have written it to conform to the tools standards (Eg. using the Javadoc keywords @version). I am sure once you look up how to do it you will better understand what I mean.

3. "The application should ask the user to enter annual sales, and it should display the total annual compensation." : I am not quite sure if this task requires you to create a GUI for the user to enter in the sales, but I will assume they do NOT as you are still learning the basics of the language. And because you do not have to great a GUI this question is quite straight forward... I will run you through a quick layout of how I would expect this task to be laid out. You will have a number of variables, the first being a "constant" variable that will hold the fixed monthly salary of $4000. The second variable will be a variable which will hold the value given by the user (salesperson annual sales). You will then be required to work out the commission of total sales using basic math and will store that value into another variable. And then finally you will have a variable that has the the monthly salary over a period of 12 months + the total commission of all sales. Note: You can have as many variables as you desire, just make sure that when creating them that you do not create to many unnecessary or too little variables.

I really hope I have helped abit, at least to get you started. Try working with the notes your institution provides you with this way you won't go too far ahead into the work and your notes will usually focus on the knowledge you will require to complete the tasks given to you.... Have a go at this one and please don't hesitate to write back if you experience any problems or if you don't understand something.

Peace Out Posted Image
  • 0

#3
rhymin

rhymin

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 210 posts
Thank you so much, I am working on some code and I know it will be right the first time, but I'll post what I get.
  • 0

#4
rhymin

rhymin

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 210 posts
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;

// This program will calculate the total annual compensation of a salesperson.

public class CommissionCalculation1
{

// This is the beginning of the main method

public static void main(String[] args)
{
// This method displays the salesperson's fixed annual salary.

double salary;
salary = 4000;

System.out.println("The Salesperson earns a fixed monthly salary of $"
+ salary + ".");
}
}
  • 0

#5
rhymin

rhymin

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 210 posts
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.
  • 0

#6
rhymin

rhymin

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 210 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.
  • 0

#7
rhymin

rhymin

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 210 posts
Well, this is what I have. I know it's wrong because I only used one class, but I didn't know how to do it any other way. Here is what I have:

package commissioncalculation1;

// This program will calculate the total annual compensation of a salesperson.
//  Author - Brad Eyman
import java.util.Scanner;

public class CommissionCalculation1 
{
        
    // This is the beginning of the main method
    public static void main(String[] args) 
    {
        
        // This method displays the salesperson's fixed annual salary
        double monthlySalary; // Salesperson's fixed monthly salary
        monthlySalary = 4000;
        double annualSalary; // Salesperson's fixed annual salary
        annualSalary = monthlySalary * 12; // 12 represents months in a year
        
        System.out.println("The Salesperson earns a fixed monthly salary of $" 
                           + monthlySalary + ".");
        System.out.println("The Salesperson earns a fixed annual salary of $"
                           + annualSalary + ".");
                           
        // This method displays the salesperson's commission rate
        int commission;
        commission = 20;
        
        System.out.println("The Salesperson will receive a commission of "
                           + commission + "%.");
        
        // Creates Scanner to collect annual sales input from salesperson
        Scanner input = new Scanner(System.in);
        
        double annualSales; // Salesperson's annual sales
        
        System.out.print("Enter annual sales: ");
        annualSales = input.nextDouble();
        
        double commissionCalc; // Calculates commission of annual sales
        double percentCalc = commission/100.0; // Makes commission calculable
        commissionCalc = annualSales * percentCalc;
        
        System.out.println("The annual sales of the salesperson is $" 
                          + commissionCalc + " using a " + commission 
                          + "% commission.");
        
        double totalAnnualSum; // Salesperson's total annual compensation
        totalAnnualSum = annualSalary + commissionCalc;
        
        System.out.println("The total annual compensation of the salesperson " 
                         + "is: $" + totalAnnualSum + ".");
        
    } // end main method
} // end class CommissionCalculation1

Edited by rhymin, 25 February 2013 - 06:28 PM.

  • 0

#8
rhymin

rhymin

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 210 posts
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?
  • 0

#9
rhymin

rhymin

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 210 posts
Can anyone help with this?
  • 0

#10
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,354 posts
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 Posted Image
  • 0

#11
rhymin

rhymin

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 210 posts
Sorry about that, I had a lot of questions as I was going through the code and just posted them at will. Next time I will try to gather all of my questions at once and make one nice post. Thank you so much for your time and I will work on this.

Edited by rhymin, 26 February 2013 - 05:07 AM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP