所以我有一个家庭作业,要求我做以下事情:
这是我必须创建的表的一个示例,它假设年总销售额为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>>
上表就是一个例子!根据输入的年销售额,它会有所不同。
应用程序还必须满足以下技术要求:
基本上,我是在前几周的任务基础上构建的,该任务是构建一个计算销售人员年度总薪酬的应用程序。
所以,我遇到的问题是,我对此非常困惑。我得到了一个错误,我将在下面显示,当我运行程序时,我得到了这个结果:
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));
}
}
所以,这对我来说根本不起作用,我仍然需要我得不到的桌子来工作。我也需要它来满足需求,但对我来说,似乎我有很多代码只是无所事事,或者我在复制一切,但我不知道如何清理它。
我不指望你们为我做这件事,我只是需要帮助,因为我变得如此迷茫和沮丧!!
谢谢你能给我的任何帮助!
这一行中的错误
System.out.println(annualSales) + "\t" + calculate.printAnnualCompensation();
是您尝试使用操作符的左侧类型为
val
。您想做这样的事情:
System.out.println(annualSales + "\t" + calculate.printAnnualCompensation());
问题内容: 我的配置:Win7 + Python 2.6 + eclipse + PyDev 如何在以下位置启用Unicode打印语句: Eclipse中的PyDev控制台 空闲的Python GUI 打印语句示例: 结果如下: 问题答案: 对于Eclipse Unicode控制台支持: 添加到eclipse安装目录中。 在日食中-确保选择UTF-8 在日食中-确保选择了UTF-8 从-更改为 确
控制台日志是一个强大的方法,用来检查您的页面或应用程序。让我们从console.log()开始,探索其他高级用法。 TL;DR 使用console.log()进行基本日志记录 使用console.erroe()和console.warn()获取醒目的内容 使用console.group()和console.groupEnd()来分组相关消息,避免混乱 使用console.assert()显示条件语
问题语句:我有一个在Xcode中运行的程序,它有一堆print()语句,可以很好地将输出打印到调试控制台。然而,我希望也能够将这些输出重定向到一个文件,这样我就可以让用户将它们发送给我,作为调试的一种方式。 SO上找到的解决方案使我可以将输出重定向到文件,但调试控制台输出将丢失。 问:我想要我的蛋糕和吃它。我希望能够将print()语句重定向到调试控制台和文件。 所以我有引用:https://st
我试图使用TDD(测试驱动开发)与。当我使用时,不会到控制台。 我正在使用来运行它。 似乎说默认情况下它应该工作:http://pytest.org/latest/capture.html 但是: 没有任何东西被打印到我的标准输出控制台(只是正常的进度和多少测试通过/失败)。 我正在测试的脚本包含打印: 在模块中,默认情况下打印所有内容,这正是我所需要的。但是,出于其他原因,我希望使用。 有人知道
由来 编码中我们常常需要调试输出一些信息,除了打印日志,最长用的要数System.out和System.err 比如我们打印一个Hello World,可以这样写: System.out.println("Hello World"); 但是面对纷杂的打印需求,System.out.println无法满足,比如: 不支持参数,对象打印需要拼接字符串 不能直接打印数组,需要手动调用Arrays.to
当我运行laravel黄昏测试时,cmd会显示很多控制台消息,例如: 我怎样才能防止这种情况?在测试时,它会在每一页中显示这一点