佣金计算器问题

时间:2017-02-08 16:36:23

标签: java jgrasp

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;

我需要计算monthSales,但我不确定如何在循环中添加所有当前销售额。当用户提出销售时,还需要显示佣金率。我只是不确定如何做到这一点。我正在使用Jgrasp / java。

1 个答案:

答案 0 :(得分: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);