gpt4 book ai didi

Java 在此作业的一部分上卡住了

转载 作者:太空宇宙 更新时间:2023-11-04 13:32:29 25 4
gpt4 key购买 nike

这是我的作业:

Modify the Week Two Java™ application using Java™ NetBeans™ IDE to meet these additional and changed business requirements:
- The company has recently changed its total annual compensation policy to improve sales.
- A salesperson will continue to earn a fixed salary of $75,000. The current sales target for every salesperson is $140,000.
- The sales incentive will only start when 80% of the sales target is met. The current commission is 25% of total sales.
- If a salesperson exceeds the sales target, the commission will increase based on an acceleration factor. The acceleration factor is 1.25.
- The application should ask the user to enter annual sales, and it should display the total annual compensation.
- The application should also display a table of potential total annual compensation that the salesperson could have earned, in $5000 increments above the salesperson's annual sales, until it reaches 50% above the salesperson's annual sales.

一切正常,我唯一坚持的就是让该表达到销售人员年销售额的 50%。例如,如果总销售额为 100,000 美元,则表格将显示总销售额和报酬,直到 150,000

这是源代码

DriverCalculator.java

import java.util.Scanner;


public class DriverCalculator {
public static void main(String args[]){
double annualSales;
SalesPerson person;
Scanner input=new Scanner(System.in);
System.out.print("Please enter your total sales for the year: ");
annualSales=input.nextDouble();
person=new SalesPerson(annualSales);
System.out.println(" Your total compensation for the year: $"+String.format("%.2f", person.getTotalAnnualCompensation()));

System.out.println("Total Sales Total Compensation");
annualSales= annualSales;
for(int i=0;i<11;i++){
person=new SalesPerson(annualSales);
System.out.println("$"+ annualSales+" "+"$"+String.format("%.2f", person.getTotalAnnualCompensation()));
annualSales+=5000;
}
}
}

销售人员.java

public class SalesPerson {
// create variable (fixedSalary)
double fixedSalary;
// variable of the value of sale person's annual sales
double annualSales;
//commission that is earned
double commission;
//The target for sales that must be reached by sales person
double target;
public SalesPerson(double annualSales){
this.annualSales=annualSales;
target=140000;
commission=0;
if(annualSales>target*0.8){
if(annualSales<target)commission=0.25*annualSales;//The current commission 25% of total sales.
else commission=0.25*1.25*annualSales;//The current commission (0.25*1.25)% of total sales.
}
fixedSalary=75000;// set fixed salary is 75000$
}
public double getTotalAnnualCompensation(){// calculate The total annual compensation is the fixed salary plus the commission earned
return fixedSalary+commission;
}
}

最佳答案

您需要动态计算“i”的上限,而不是硬编码。我认为

annualSales= annualSales;
int upperlimit = (annualSales/2)/5000;
for(int i=0;i<=upperlimit;i++){
person=new SalesPerson(annualSales);
System.out.println("$"+ annualSales+" "+"$"+String.format("%.2f", person.getTotalAnnualCompensation()));
annualSales+=5000;
}

关于Java 在此作业的一部分上卡住了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32031576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com