Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Java Assignment Question

    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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Assignment Question

    We'd be glad to help you. No one will do the assignment for you, of course, but if you have any specific questions about Java or about the assignment that we can answer, please feel free to ask and we'll do the best we can to help.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Assignment Question

    cross-posted: Java Assignment Question

    I'm suspecting that you're just dumping your homework all over the internet. Please prove me wrong by asking specific questions as requested above.

  4. #4
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    Sorry about that, I didn't think my message posted the first time so I found a different forum to post in.

    I am working on code right now and will post what I have (I know it won't be right the first time). Thank you so much for your time.

  5. #5
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    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 + ".");
    }
    }

  6. #6
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    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.

  7. #7
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    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.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Assignment Question

    As per your instructions you will need at least 2 classes, one perhaps a SalesPerson class that has code to accept annual sales and then calculates his commission and the other class a control class that has the main method that uses SalesPerson objects.

    Also you will want to use [code] [/code] tags around your code to help it retain its formatting. Please see the link in my signature to learn more on this.

  9. #9
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    Thanks for your time, but I have no idea how to use 2 classes. I feel like this is way too hard for a person to write that has been in a Java class for only a week and a half. Very discouraging to say the least. :(

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Assignment Question

    It is hard learning to program, but with effort it is do-able and definitely worth it. Please have a look at the Java tutorials to learn some of the basics and some more advanced concepts: The Really Big Index

    Keep trying and please come back with your specific questions.

  11. #11
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    First question, what is the very first line?: package commissioncalculation1;

    I know that commissioncalculation is the class because I created the name, but I haven't seen the word "package" at all in any example or video tutorial in class.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Assignment Question

    Quote Originally Posted by rhym1n View Post
    First question, what is the very first line?: package commissioncalculation1;
    This is the package that holds your program. I think I saw that you were using NetBeans, and it likely asked you for a package name and automatically created this. If you look on your computer, you'll find a subdirectory with the same name that holds your java and your class files. It is a good idea to place your code in packages like this, so don't change this.

    I know that commissioncalculation is the class because I created the name
    Actually it is different from the class name. Remember that capitalization matters with Java.

    ... but I haven't seen the word "package" at all in any example or video tutorial in class.
    Please click on the link that I provided in my answer above this one, and search on the term, packages.

  13. #13
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    Thank you for clarifying that!

  14. #14
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    Well, at least some good news. I wrote the entire code under one class (I know, it's not what the assignment required), but all of the calculations, display messages, and even the user input work correctly. I'm sure the code is very sloppy to someone like you, and maybe I added a bit too much at parts. But, do you have any advice or corrections on the code I do have, and also, do I have enough documentation? Here it is:

    Java Code:
     
    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
            commissionCalc = annualSales * .2;
            
            System.out.println("The annual sales of the salesperson is $" 
                              + commissionCalc + " using a 20% 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
    Last edited by rhym1n; 02-25-2013 at 06:46 AM.

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java Assignment Question

    Quote Originally Posted by rhym1n View Post
    Java Code:
     
            int commission;
            commission = 20;
    
            commissionCalc = annualSales * .2;
            
            System.out.println("The annual sales of the salesperson is $" 
                              + commissionCalc + " using a 20% commission.");
    This makes me feel itchy ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    Jos, I'm not sure what you mean?

    I know the code probably looks bad, but that's the only way I know how to make it work.

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java Assignment Question

    Quote Originally Posted by rhym1n View Post
    Jos, I'm not sure what you mean?

    I know the code probably looks bad, but that's the only way I know how to make it work.
    Suppose the commission percentage changes to, say, 25 percent, you don't only have to change the number 20 to 25, but you also have to change the numer .2 to .25; why not let the computer do it?
    Java Code:
    double factor= commission/100.0;
    commissionCalc = annualSales * factor;   
    System.out.println("The annual sales of the salesperson is $" + commissionCalc + " using a " + commission + "% commission.");
    kind regards,

    Jos

  18. #18
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    Oh wow, thank you so much. I wasn't sure on the formula for making it say 20% and also multiplying by .2, but I see now that the commission/100.0 does it. Thank you for that.

  19. #19
    rhym1n is offline Member
    Join Date
    Feb 2013
    Posts
    32
    Rep Power
    0

    Default Re: Java Assignment Question

    Another question, when I enter the input for annual sales (and it performs the calculation), how do i make it use a comma since it's in the thousands range?

    Also, if I type in say $50000.23, it brings up the number $58000.046. I know I saw this before but now I can't find it, how do I make this round up to the higher number and show just 2 decimal places, just like actual money?

  20. #20
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java Assignment Question

    Quote Originally Posted by rhym1n View Post
    Another question, when I enter the input for annual sales (and it performs the calculation), how do i make it use a comma since it's in the thousands range?

    Also, if I type in say $50000.23, it brings up the number $58000.046. I know I saw this before but now I can't find it, how do I make this round up to the higher number and show just 2 decimal places, just like actual money?
    It is locale dependent (e.g. overhere we use a 'decimal comma' instead of a 'decimal dot'); read the API documentation for the Decimal format class; it can do rounding too; don't start messing around by multiplying by 100, take the integer part and divide by 100 again; it doesn't work ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 1 of 2 12 LastLast

Similar Threads

  1. Question about a simple Java programing assignment.
    By ron_j_m in forum New To Java
    Replies: 12
    Last Post: 04-27-2011, 12:03 AM
  2. Assignment of char and int question
    By BillyB in forum New To Java
    Replies: 5
    Last Post: 01-21-2011, 01:42 PM
  3. First Assignment and already stuck....Newbie Question
    By Danieldcc in forum New To Java
    Replies: 5
    Last Post: 09-24-2010, 11:44 PM
  4. i have a question on my assignment??(java)
    By javanew in forum New To Java
    Replies: 4
    Last Post: 03-27-2010, 11:15 PM
  5. Question about school assignment
    By wata in forum New To Java
    Replies: 7
    Last Post: 08-18-2009, 02:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •