Results 1 to 20 of 22
Thread: Java Assignment Question
- 02-24-2013, 10:17 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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.
-
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.
-
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.
- 02-25-2013, 04:04 AM #4
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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.
- 02-25-2013, 04:25 AM #5
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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 + ".");
}
}
- 02-25-2013, 04:26 AM #6
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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.
- 02-25-2013, 04:28 AM #7
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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.
-
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.
- 02-25-2013, 05:33 AM #9
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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. :(
-
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.
- 02-25-2013, 06:02 AM #11
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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.
-
Re: Java Assignment Question
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.
Actually it is different from the class name. Remember that capitalization matters with Java.I know that commissioncalculation is the class because I created the name
Please click on the link that I provided in my answer above this one, and search on the term, packages.... but I haven't seen the word "package" at all in any example or video tutorial in class.
- 02-25-2013, 06:21 AM #13
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
Re: Java Assignment Question
Thank you for clarifying that!
- 02-25-2013, 06:38 AM #14
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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 CommissionCalculation1Last edited by rhym1n; 02-25-2013 at 06:46 AM.
- 02-25-2013, 08:56 AM #15
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
- 02-25-2013, 10:43 AM #16
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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.
- 02-25-2013, 11:05 AM #17
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
Re: Java Assignment Question
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?
kind regards,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.");
Jos
- 02-25-2013, 12:04 PM #18
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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.
- 02-25-2013, 12:13 PM #19
Member
- Join Date
- Feb 2013
- Posts
- 32
- Rep Power
- 0
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?
- 02-25-2013, 12:25 PM #20
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
Re: Java Assignment Question
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Question about a simple Java programing assignment.
By ron_j_m in forum New To JavaReplies: 12Last Post: 04-27-2011, 12:03 AM -
Assignment of char and int question
By BillyB in forum New To JavaReplies: 5Last Post: 01-21-2011, 01:42 PM -
First Assignment and already stuck....Newbie Question
By Danieldcc in forum New To JavaReplies: 5Last Post: 09-24-2010, 11:44 PM -
i have a question on my assignment??(java)
By javanew in forum New To JavaReplies: 4Last Post: 03-27-2010, 11:15 PM -
Question about school assignment
By wata in forum New To JavaReplies: 7Last Post: 08-18-2009, 02:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks