我有一个程序,根据基本工资和佣金销售计算员工年薪。我想让程序更进一步,创建一个arrayList,它将询问员工姓名,然后创建一个数组,存储程序中的值,并为输入的每个员工姓名打印出这些值。
我想我需要创建一个for或else循环来收集数据。问题是我不知道该怎么做以及如何创建数组。我有两个班:
我的佣金变量和计算的1个等级:
package Commissions;
public class Calculations {
double totalSales;
private double comRate = 0.025;
private double annualSal = 80000;
private double salesTarget = 120000;
private double acceleration = 0.015;
private double compensation;
public Calculations (double TotalSales) {
this.totalSales = totalSales;
}
public double getCommissionCalc () {
if (totalSales >= salesTarget) {
compensation = (annualSal + (totalSales * (comRate + acceleration)));
return compensation;
} else if (totalSales >= salesTarget * .8) {
compensation = (annualSal + (totalSales * comRate));
return compensation;
} else {
compensation = annualSal;
return compensation;
}
}
}
我的主要和用户输入的1个课程
package Commissions;
import java.text.NumberFormat;
import java.util.*;
public class paycheck {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
NumberFormat nf = NumberFormat.getCurrencyInstance();
System.out.println("Enter the employee name: ");
long empName = input.nextLong();
mediaArray[empName];
System.out.println("Enter your total sales for the year: ");
double totalSales = input.nextDouble();
System.out.println("\r");
Calculations c = new Calculations (totalSales);
System.out.println("Your Total compensation with your annual sales is: " + nf.format(c.getCommissionCalc()));
System.out.println("\r");
System.out.println("If you were to increase your sales you could earn even more money!");
System.out.println("\r");
double i = totalSales + 5000;
double finish = totalSales * 1.5;
while (i <= finish) {
c.totalSales = i;
System.out.println("If you were to increase your sales commission to " + nf.format(i) + " you could earn: " + nf.format(c.getCommissionCalc()));
i = i + 5000;
}
}
}
答案 0 :(得分:0)
根据我对你的问题的理解,这是代码,必须纠正一些事情,因为你说输入名称,但需要长时间作为输入:
textFailde.text = "0"
textFilde1.text = "0"
previousValues.append(textFailde.text ?? String(0))
previousValues1.append(textFilde1.text ?? String(0))
self.lblZeroUs.text = String(0)
self.lblZeroThey.text = String(0)
if self.previousValues.count > 0 {
let subtracted = (Int(self.lblZeroUs.text!)!) - (Int(self.previousValues.last!))!
self.previousValues.removeLast()
self.lblZeroUs.text = "\(subtracted)"
}
else if self.previousValues1.count > 0 {
let subtracted2 = (Int(self.lblZeroThey.text!)!) - (Int(self.previousValues1.last!))!
self.previousValues1.removeLast()
self.lblZeroThey.text = "\(subtracted2)"
}