Results 1 to 14 of 14
Thread: math help
- 02-01-2013, 09:00 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
math help
I'm writing a java program for a school assignment. I have everything completed except getting the program to calculate the sales commission for each $5000 increment, it takes the first one and just copies it to the following increments.
What did I do wrong?
WHen i run this program it displays the "I'm sorry..." text if the number entered for sales is less than the goal (960,000).Java Code:import java.util.Scanner; public class Compensation { /* The total compensation of the Salesman is calculated by this equation: * Annual Compensation = 60000 + (.025 * Sales) */ private static double salary = 60000; //Salary is the annual salary of $60k private static double commission = 0.025; //commission is .025 of sales private static double target = 1200000; //Target sales amount to trigger accel factor private static double goal = 960000; //Goal to start the commission bonus public static void main(String[] args) { //Scanner to capture keyboard input Scanner keyboard = new Scanner(System.in); //Display the Salary System.out.println("The Salesman's annual compensation is found by this formula:"); System.out.println("Compensation = Salary + (Commission * Sales.)"); System.out.println("The saleman's annual salary is $60,000."); //Display the Commission System.out.println("The Salesman's commission is 25% of his sales."); System.out.println("To find the annual compensation, we need the number of sales for the year."); //Get the sales ammount System.out.println("What is the annual sales amount for this salesman? "); double sales = keyboard.nextDouble(); if (sales >= goal) { commission = commission + 1.25; } double compensation = salary + (commission * sales); if (sales < goal) { System.out.println("I'm sorry, the salesman did not meet the target sales and does not receive commission."); System.out.println("The salesman's annual compensation this year will just be the salary of $" +Double.toString(salary)); } else { for (double amount = sales; amount <= sales + 50000; amount+= 5000){ System.out.println(amount + " Compensation is $" + (compensation)); } } } }
If the number entered is more than 960000 it displays the increments correctly but doesn't calculate the sales commission for each increment.
Java Code:What is the annual sales amount for this salesman? 1000000 1000000.0 Compensation is $1335000.0 1005000.0 Compensation is $1335000.0 1010000.0 Compensation is $1335000.0 1015000.0 Compensation is $1335000.0 1020000.0 Compensation is $1335000.0
- 02-01-2013, 09:15 PM #2
Re: math help
If we use 1,000,000 as an example Sales amount, what would you expect to have printed out?
Are you saying that for every $50,000 in sales, the comission amount should increase by 1.25%?
- 02-01-2013, 09:59 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Re: math help
Yes, there's an acceleration factor of 1.25 after the salesman makes or exceeds 1.2 million in sales. The factor intervals are up to us, I used 5000, but it makes more sense if we use 100,000 for the intervals.
So as shown in the second code box i posted for each interval the compensation should be salary + (commission * sales), or 60000 + (.025 * sales) where sales is the number entered.
so if I or someone enters 1.5 mill as the sales, it should give the 1.5 mill number as shown and then Compensation is $153,750.00 or $60,000 + (.0625 * 1500000) at 1500000 the acceleration factor increases the commission from 2.5% to 6.25% (.0625) using the 100k increments
Does that make sense?Java Code:1000000.0 Compensation is $85000.00 1100000.0 Compensation is $87500.00 etc.
Last edited by kormath; 02-01-2013 at 10:05 PM.
- 02-01-2013, 10:14 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
Re: math help
You should consider your "for"-loop. There you display increasing sales but always the same compensation.
- 02-01-2013, 11:13 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Re: math help
I thought line 30 and 31 would take care of that.
- 02-02-2013, 07:24 AM #6
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
- 02-03-2013, 04:15 PM #7
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Re: math help
so i need to add the equation in the loop? And sorry i meant line 34.
Java Code:else { for (double amount = sales; amount <= sales + 50000; amount+= 5000){ double compensation = salary + (commission * sales); System.out.println(amount + " Compensation is $" + (compensation));
- 02-06-2013, 08:52 PM #8
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Re: math help
I was able to add the formula for the compensation to the loop without throwing out errors, but it still won't calculate for each increment of the loop. Any other ideas i can try?
Could this be done without a loop?Java Code:if (sales < goal) { System.out.println("I'm sorry, the salesman did not meet the target sales and does not receive commission this year."); System.out.println("The salesman's annual compensation will only be his fixed salary of $" +Double.toString(salary)); } else { for (double amount = sales; amount <= sales + 500000; amount+= 100000) { double compensation = salary + (commission * sales); System.out.println(amount + " Compensation is $" + (compensation));
My goal is to have the program display the sales input by the user and calcualte the compensation for that input, as well as 5 increments above that input.
Java Code:**example** Total Sales Total Compensation 1,000,000 85,000 1,100,000 87,500 1,200,000 90,000 1,300,000 108,750 1,400,000 130,000 1,500,000 153,750
- 02-09-2013, 03:12 PM #9
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Re: math help
Okay so i fixed my error in the code not calculating in the loop. I forgot to replace the sales keyword with the amount keyword I created in the loop. Now that part is working perfectly.
However, i need to have this printed in a table format. I've made the "table" but when i add the amount and compensation keywords to print in the columns, i get this error.
Error text -
System.out.println("%-15s $15s %n", amount, compensation);
method PrintStream.println(Object) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(String) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(char[]) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(double) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(float) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(long) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(int) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(char) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println(boolean) is not applicable
(actual and formal argument lists differ in length)
method PrintStream.println() is not applicable
(actual and formal argument lists differ in length)
Here's the "table" code
Where did is screw up this time?Java Code:else { for (double amount = sales; amount <= sales + 500000; amount+= 100000) { double compensation = salary + (commission * amount); // System.out.println(amount + " Compensation is $" + (compensation)); /* * Formatting for the output of the compensation and sales * Code obtained from Free Java Course (2013) * http://www.homeandlearn.co.uk/java/java_formatted_strings.html */ //Code for the column headings String heading1 = "Sales Amount"; String heading2 = "Salesman's Comp"; String divider = "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤"; //Code for pringing the headings in the correct columns System.out.println(""); System.out.printf("%-15s %15s %n", heading1, heading2); System.out.println(divider); //Code to print the sales and comp info under the headings System.out.println("%-15s $15s %n", amount, compensation); System.out.println(divider);
-
Re: math help
It looks to me a simple error -- you've got println in one spot where printf should be.
- 02-09-2013, 10:42 PM #11
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Re: math help
ah I see. Thanks! that fixed it.
-
Re: math help
You're welcome!
- 02-16-2013, 12:43 PM #13
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Re: math help
another question on this. I'm supposed to use the output from this in another class. That class is an array, and it's supposed to ask for 2 names, then print the sales entered for those 2 names, and show the difference in the sales.
I've gotten this to work by itself printing out the keyboard input, but cannot figure out how to use the info from the Compensation class posted previously in the array class. I've read you can extend the class, but NetBeans gives me errors when i do this.
Here's the array class:
Java Code:package compensation; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; /** * * @author tolsen */ public class array { public static void main(String[] args) { //Scanner object for saving keyboard input Scanner keyboard = new Scanner(System.in); //Number of employees final int peeps = 2; //Array to hold the names and sales info String[] name = new String[peeps]; double[] sales = new double[peeps]; for (int i = 0; i < peeps; i++) { System.out.print("\n What is the name of the Salesperson? "); name[i] = keyboard.next(); System.out.print("\n What is the annual sales for this Salesperson? "); sales[i] = keyboard.nextDouble(); } System.out.println("Name and sales of first Salesperson:"); System.out.printf("%-15s %5s %n", name[0], sales[0]); System.out.println(); System.out.println("Name and sales of second Salesperson:"); System.out.printf("%-15s %5s %n", name[1], sales[1]); System.out.println(); if (sales[0] < sales[1]){ System.out.println("The difference in sales is: " + (sales[1] - sales[0])); System.out.println(); System.out.println(name[0] + " needs to make up $" + (sales[1] - sales[0]) + " in sales."); } else if (sales[0] > sales[1]) { System.out.println("The difference in sales is: " + (sales[0] - sales[1])); System.out.println(); System.out.println(name[1] + " needs to make up $" + (sales[0] - sales[1]) + " in sales."); } } }
- 02-17-2013, 11:24 AM #14
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
Re: math help
First you should use uppercase-names for your classes to meet the common naming conventions.
To solve your problem you need to add a getter-method to the Compensation-class which returns the compensation by the sales argument. Then you need to instantiate "Compensation" from your Array-Class and call this getter-method.
Ulrich
Similar Threads
-
Math help
By stuffses in forum New To JavaReplies: 5Last Post: 03-09-2012, 01:00 AM -
Doing Math
By nicholas205 in forum New To JavaReplies: 1Last Post: 01-28-2012, 02:18 AM -
math and GUI
By urbanleg in forum AWT / SwingReplies: 3Last Post: 08-06-2011, 04:05 PM -
Math.cos()
By ravi1 in forum New To JavaReplies: 5Last Post: 03-27-2011, 02:52 PM -
Create Math.sin without math.sin
By vudoo in forum New To JavaReplies: 11Last Post: 12-07-2010, 06:23 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks