2017-02-08 333 views
-1
import java.util.Scanner; // imports scanner class to read user input 

public class commissionsCalc { //opens class 



public static void main(String[] args){// opens main 


    double commissionsRate; 
    int basePay = 1000; 
    int monthlySales = 0; 
    int counter = 0; 
    double grossPay = 0; 
    double commissionsAmt; 
    int curSale = 0; 
    Scanner input = new Scanner(System.in); 

    //System.out.println("Please enter a sale amount or type -1 to finish entering sales and calculate gross pay"); 



    System.out.println("Please enter a sale amount or type -1 to finish entering sales and calculate gross pay"); 
    curSale = input.nextInt(); 

    while (curSale !=-1) {//opens while loop 

    monthlySales += curSale; 
    counter++; 

    System.out.println("Please enter a sale amount or type -1 to finish entering sales and calculate gross pay"); 
    curSale = input.nextInt(); 

    }//closes while loop 

    if (monthlySales < 5000){//opens if statement 
    commissionsRate = .06; 
    }//closes if statement 

    else if (monthlySales > 5000 && monthlySales <10000) {//opens else if statement 
    commissionsRate = .08; 

    } 
    else if (monthlySales >= 10000) {//opens else if statement 
    commissionsRate = .10; 

我需要計算monthlySales,但我不知道如何將我的循環中的所有當前銷售額相加。當用戶提出銷售時,還需要顯示佣金率。我只是不知道我該怎麼做。我正在使用Jgrasp/java。問題計算器問題

+0

你加入你的curSale您montlySales在電流回路 – Coder

+0

是現在即時通訊不知道我怎麼打印我從所有的數字讓屏幕值 –

+0

可以嗎發佈完整的代碼,以便我可以採取刺探措施? – Coder

回答

0

包括這在你的代碼

commissionsAmt = monthlySales*commissionsRate; 
grossPay = basePay + commissionsAmt; 
System.out.println("Monthly sales amount is: "+ monthlySales); 
System.out.println("Commision rates to those sales: "+ commissionsRate); 
System.out.println("Commission amount made "+ commissionsAmt); 
System.out.println("Gross pay "+ grossPay); 
+0

我得到一個錯誤消息說:java:56:錯誤:變量commissionsRate可能沒有被初始化 –

+0

我有一個錯字。我現在更新它,並初始化佣金率爲零 – Coder

+0

再一次感謝,我如何獲得它打印我的基本工資? –