2015-08-16 18 views
0

的一部分卡住這是我的任務:Java的這個分配

修改使用Java™的NetBeans™IDE,以滿足這些額外的和變化的業務需求的第二週Java™應用程序:
- 公司擁有最近改變了其年度薪酬總額政策以改善銷售。
- 銷售員將繼續獲得75,000美元的固定工資。目前每位銷售員的銷售目標是14萬美元。
- 銷售激勵只會在滿足80%的銷售目標時開始。目前的佣金佔總銷售額的25%。
- 如果銷售人員超過銷售目標,佣金將根據加速因子增加。加速因子是1.25。
- 應用程序應該要求用戶輸入年銷售額,並且應顯示年度總補償。
- 應用程序還應該顯示銷售人員可能獲得的潛在年度總薪酬表,以高於銷售員年銷售額5000美元爲增量,直至達到銷售人員年銷售額的50%。

一切正常,我堅持的唯一辦法是讓表達到銷售人員年銷售額的50%。因此,例如,如果總銷量爲100,000表將顯示銷售總額和補償$至150000

這裏是源代碼

DriverCalculator.java

import java.util.Scanner; 


public class DriverCalculator { 
    public static void main(String args[]){ 
     double annualSales; 
     SalesPerson person; 
     Scanner input=new Scanner(System.in); 
     System.out.print("Please enter your total sales for the year: "); 
     annualSales=input.nextDouble(); 
     person=new SalesPerson(annualSales); 
     System.out.println(" Your total compensation for the year: $"+String.format("%.2f", person.getTotalAnnualCompensation())); 

     System.out.println("Total Sales    Total Compensation"); 
     annualSales= annualSales; 
     for(int i=0;i<11;i++){ 
      person=new SalesPerson(annualSales); 
      System.out.println("$"+ annualSales+"    "+"$"+String.format("%.2f", person.getTotalAnnualCompensation())); 
      annualSales+=5000; 
     } 
    } 
} 

SalesPerson.java

public class SalesPerson { 
// create variable (fixedSalary) 
double fixedSalary; 
// variable of the value of sale person's annual sales 
double annualSales; 
//commission that is earned 
double commission; 
//The target for sales that must be reached by sales person 
double target; 
public SalesPerson(double annualSales){ 
    this.annualSales=annualSales; 
    target=140000; 
    commission=0; 
    if(annualSales>target*0.8){ 
     if(annualSales<target)commission=0.25*annualSales;//The current commission 25% of total sales. 
     else commission=0.25*1.25*annualSales;//The current commission (0.25*1.25)% of total sales. 
    } 
    fixedSalary=75000;// set fixed salary is 75000$ 
} 
public double getTotalAnnualCompensation(){// calculate The total annual compensation is the fixed salary plus the commission earned 
    return fixedSalary+commission; 
} 
} 
+0

驅動Calculator.java –

+0

爲什麼'我<11'?如果該人的銷售額爲100000美元,那麼可能11是正確的限制,但對其他情況則不正確。這是問題嗎?我猜測它輸出的所有值都是正確的,但它只是不能輸出足夠多的行(或輸出太多)? – ajb

+0

at 100000 itouputs until 150000 –

回答

0

您需要動態計算'i'的上限而不是硬編碼。我認爲

annualSales= annualSales; 
int upperlimit = (annualSales/2)/5000; 
    for(int i=0;i<=upperlimit;i++){ 
     person=new SalesPerson(annualSales); 
     System.out.println("$"+ annualSales+"    "+"$"+String.format("%.2f", person.getTotalAnnualCompensation())); 
     annualSales+=5000; 
     } 
+0

當輸入100000時,它只能達到145000,因此它只比銷售人員年銷售額高出45%......我還輸入了更多的數字,他們給出的銷售額高出銷售員年銷售額的45% –

+0

我試過了......它的一個我輸入的每一個數字都是簡短的... Anuswadh你知道它爲什麼這麼做嗎? –

+0

測試結果:請輸入您的總銷量爲一年:100000 你的年度報酬總額:$ 75000.00 銷售總額合計薪酬 $ 100000.0 $ 75000.00 $ 110000.0 $ 75000.00 $ 120000.0 $ 105000.00 $ 130000.0 $ 107500.00 $ 140000.0 $ 118750.00 $ 150000.0 $ 121875.00 $ 160000.0 $ 125000.00 $ 170000.0 $ 128125.00 $ 180000.0 $ 131250。00 $ 190000.0 $ 134375.00 BUILD SUCCESSFUL(總時間:3秒) –