Java 正在尝试在控制台中打印佣金和表格
因此,我有一个家庭作业,要求我做以下几点: 该公司最近改变了年度总薪酬政策,以提高销售额 销售人员将继续获得55000.00美元的固定工资。目前每位销售人员的销售目标为100000.00美元。 只有达到80%的销售目标,销售激励才会开始。目前的佣金占总销售额的14%。 如果销售人员超过销售目标,佣金将根据加速系数增加。加速度系数为1.40。 应用程序应要求用户输入年度销售额,并显示年度薪酬总额。 该应用程序还应显示销售人员可能获得的潜在年薪酬表,以高于销售人员年销售额5000.00美元的增量递增,前提是其达到销售人员年销售额50%以上。 这是我必须创建的表格的一个例子,它假设年销售总额为100000.00美元。所以它看起来像这样:Java 正在尝试在控制台中打印佣金和表格,java,Java,因此,我有一个家庭作业,要求我做以下几点: 该公司最近改变了年度总薪酬政策,以提高销售额 销售人员将继续获得55000.00美元的固定工资。目前每位销售人员的销售目标为100000.00美元。 只有达到80%的销售目标,销售激励才会开始。目前的佣金占总销售额的14%。 如果销售人员超过销售目标,佣金将根据加速系数增加。加速度系数为1.40。 应用程序应要求用户输入年度销售额,并显示年度薪酬总额。 该应用程序还应显示销售人员可能获得的潜在年薪酬表,以高于销售人员年销售额5000.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>>
因此,在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));
}
}
所以,这对我来说根本不起作用,我仍然需要那张我拿不到的桌子来工作。我也需要它来满足需求,但对我来说,似乎我有很多代码只是无所事事,或者我在复制所有东西,但我不知道如何清理它
我不希望你们为我做这件事,我只是需要帮助,因为我太迷茫和沮丧了
谢谢你能给我的任何帮助 这行中的错误
System.out.println(annualSales) + "\t" + calculate.printAnnualCompensation();
System.out.println(annualSales + "\t" + calculate.printAnnualCompensation());
您尝试将+运算符与void类型的左侧一起使用。你想做这样的事情:
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>>