试图在控制台

时间:2015-11-08 05:12:15

标签: java

所以我做了一项家庭作业,要求我做以下事情:

  • 公司最近改变了年度薪酬总额以提高销售额
  • 销售人员将继续获得55,000.00美元的固定工资。每个销售人员的当前销售目标是$ 100,000.00。
  • 销售奖励仅在满足80%的销售目标时开始。目前的佣金占总销售额的14%。
  • 如果销售人员超过销售目标,佣金将根据加速因子增加。加速因子为1.40。
  • 应用程序应要求用户输入年度销售额,并应显示年度总薪酬。
  • 该应用程序还应显示销售人员可能获得的潜在年度报酬表,比销售人员的年销售额高出5,000.00美元,比销售人员的年销售额高出50%。

所以,这是我必须创建的表格的一个示例,它假设年度总销售额为100,000.00美元。所以它看起来像这样:

Total Sales Total Compensation
------------------------------------------------------------------
100,000 <<Program Calculated Value>>
105,000 <<Program Calculated Value>>
110,000 <<Program Calculated Value>>
115,000 <<Program Calculated Value>>
120,000 <<Program Calculated Value>>
125,000 <<Program Calculated Value>>
130,000 <<Program Calculated Value>>
135,000 <<Program Calculated Value>>
140,000 <<Program Calculated Value>>
145,000 <<Program Calculated Value>>
150,000 <<Program Calculated Value>>

上表就是一个例子!根据输入的年销售额而不同。

该应用程序还必须满足这些技术要求:

  • 除了应用程序控制类
  • 之外,应用程序应至少有一个类
  • 您的代码必须使用方法进行补偿计算
  • 源代码必须演示使用条件和循环结构
  • 应该有适当的文件

基本上,我是在前几周的任务之上构建的,这是为了构建一个计算销售人员年度总薪酬的应用程序。

  • 销售人员将获得55,000.00美元的固定薪酬
  • 销售人员还将获得佣金作为销售奖励。佣金是销售人员年销售额的百分比。目前的佣金占总销售额的14%。
  • 年度总薪酬是固定工资加上赚取的佣金。

所以,我遇到的问题是,我对此非常困惑。我收到一个错误,我将在下面显示,当我运行程序时,我得到了这个结果:

run:
This is a console based application that calculates the total annual compensation of a salesperson.
Just follow along with the prompts, and insert the correct data.
---------------------------------------------------------------------------
Enter salesperson's annual sales
/* NOTE: I INSERTED THE BELOW VALUE OF 100000 */
100000
Total annual compensation: $69000.00
0.0
$55000.00
Total Sales      Total Compensation
ERROR: Please enter a valid sales amount.
Press enter to exit.

所以在while循环中我得到错误:

'void' type not allowed here
'void' type not allowed here
not a statement
----
(Alt-Enter shows hint)

此处显示:

while (annualSales <= annualSalesTable) {
    System.out.println(annualSales) + "\t" + calculate.printAnnualCompensation();
    annualSales = annualSales + 5000;
}

我不知道如何解决这个问题。这是代码,有两个类SalesPerson.java是主类,然后是Calculate.java:

SalesPerson.java:

package salesperson;

import java.io.IOException
import java.text.DecimalFormat;
import java.util.Scanner;

public class SalesPerson {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.println("This is a console based application that calculates the total annual compensation");
        System.out.println("Just follow along with the prompts, and insert the correct data.");
        System.out.println("----------------------------------------------\n");

        getInput(in);

        try {
            System.out.println("Press Enter to exit");
            System.in.read();
        }
        catch(IOException e) {
            e.printStackTrace();
        }
    }

    public static void getInput(Scanner in) {
        Calculate calculate = new Calculate();
        double annualSales;

        try {
            System.out.println("Enter salesperson's annual sales");
            if(in.hasNextDouble()) {
                annualSales = in.nextDouble();

                if (annualSales == 0)
                {
                    System.out.println("Please enter a valid annual sales amount.");
                }
                else 
                {
                     double tot = calculate.calcCompensation(annualSales);
                     DecimalFormat decFormat = new DecimalFormat(".00");
                     System.out.println("Total annual compensation: " + "$" + decFormat(tot));
                     /* NOTE: I DO NOT KNOW HOW TO GET annualSales to populate this! */
                     calculate.printAnnualCompensation();

                     System.out.println();
                     System.out.println("Total Sales\tTotal Compensation");

                     double annualSaleTable = annualSales * 1.5;

                     while(annualSales <= annualSaleTable) {
                         System.out.println(annualSales) + "\t" + calculate.printAnnualCompensation(); /* ERROR HERE */
                         annualSales = annualSales + 5000;
                     }
                }
            }
        }
        catch(Exception ex)
        {
            System.out.println("ERROR: Please enter a valid sales amount.");
        }
    }
}

这是Calculate.java类:

package salesperson;

import java.text.DecimalFormat;

public class Calculate {
    private double annualSales;
    private double comissionRate = 0.14;
    private double fixedSalary = 55000.00;
    private double salesTarget = 100000.00;
    private double accelerationFactor = 1.40;

    public double calcCompensation(double annualSales) {
        // Sets the annual salary to multiply by commission rate and then assign the total to currentComm
        double currentComm = annualSales * comissionRate;
        // Adds currentComm variable to the fixSalary variable and assigns that total to the "total" variable
        double total = fixedSalary + currentComm;

        return total;
    }

    public double getCommission() {
        return this.annualSales * this.comissionRate;
    }

    public double annualSales(double anSales) {
        annualSales = anSales;
        return annualSales;
    }

    public void printAnnualCompensation() { /* THIS IS THROWING ERROR ON MAIN CLASS */
        DecimalFormat decFormat = new DecimalFormat(".00");

        /** 
          * Total sales that is less than 80% of the target = no commission
          * Total sales that is between 80% of the target and the less than the target - 14%
          * Total sales that is equal or exceeds the target sales is 14% * 1.4 or 19.6%
         */

        double total = this.fixedSalary;

        // Getting the percentage of the target achieved
        double percentage = (this.annualSales / this.salesTarget) * 100;
        System.out.println(percentage);

        if (percentage < 80) {
            // Do nothing, don't get commission if the percentage is less than 80% of target
        } else if(percentage > 80 && percentage < 100) {
            // Total = annualSalary + commission
            total += getCommission();
        } else if (percentage >= 100) {
            // total = annualSalary + (commission * accelerationFactor);
            total += (getCommission() * this.accelerationFactor);
        }

        System.out.println("$" + decFormat + format(total));
    }
}

所以,这对我来说根本不起作用,我仍然需要工作台,我无法得到。我也需要它来满足要求,但对我而言,似乎我有很多代码只是无所事事或我正在复制所有内容,但我不知道如何清理它。

我不希望你们为我做这件事,我只是需要帮助这样做,因为我变得如此迷茫和沮丧!!

感谢你们给我的任何帮助!

1 个答案:

答案 0 :(得分:0)

此行中的错误

System.out.println(annualSales) + "\t" + calculate.printAnnualCompensation();

是您尝试使用+左侧的void操作符。你想做这样的事情:

System.out.println(annualSales + "\t" + calculate.printAnnualCompensation());