无法将其用于运行PAYROLL PROJECT java


package EmployeePayAppMRM;
import javax.swing.JOptionPane;
public class java 
{
public static void main(String[] args) 
{
String firstName;
String lastName;
String fullName;
String itemsSold;
String valueItems;
double basePay;
double totalPay;
double valueSold;
int numberSold;
final double ITEM_MIN = 10;
final int VALUE_MIN = 2500;
final int BONUS = 500;
firstName = JOptionPane.showInputDialog(" Enter employee's first name:");
lastName = JOptionPane.showInputDialog(" Enter employee's last name:");
fullName = JOptionPane.showInputDialog(" Enter base pay for " + firstName + " " + lastName + ":");
basePay = Double.parseDouble(fullName);
itemsSold = JOptionPane.showInputDialog(" Enter number of items sold for " + firstName + " " + lastName + ":");
totalPay = Double.parseDouble(fullName);
fullName = JOptionPane.showInputDialog(" Enter value of items sold for " + firstName + " " + lastName + ":");
valueSold = Double.parseDouble(fullName);
basePay = 1000;
if ( itemsSold > ITEM_MIN)                   //ERROR HERE (bad operand)
totalPay = (basePay + BONUS);
else if (valueSold >= VALUE_MIN)
totalPay = (basePay + BONUS);
else 
totalPay = basePay;


System.out.println("this" + firstName + " " + lastName + " " + "will be paid" + totalPay "for selling" + itemsSold "items valued at $" + valueSold);          //ERROR HERE

System.exit(0);

}
}

第一个问题是关于类型,第二个问题只是错过了一些+

  • itemsSoldString
  • ITEM_MINdouble

这样做,在之前解析它

if(Double.parseDouble(itemsSold) > ITEM_MIN)
totalPay = (basePay + BONUS);

最后,您不需要定义变量并在以后进行赋值,只需在重新组织所有变量后同时进行即可:

final double ITEM_MIN = 10;
final int VALUE_MIN = 2500;
final int BONUS = 500;
String firstName = JOptionPane.showInputDialog(" Enter employee's first name:");
String lastName = JOptionPane.showInputDialog(" Enter employee's last name:");
String fullName = JOptionPane.showInputDialog(" Enter base pay for " + firstName + " " + lastName + ":");
double itemsSold = Double.parseDouble(JOptionPane.showInputDialog(" Enter number of items sold for " + firstName + " " + lastName + ":"));
double valueSold = Double.parseDouble(JOptionPane.showInputDialog(" Enter value of items sold for " + firstName + " " + lastName + ":"));
double totalPay = 0;
double basePay = 1000;
if (itemsSold > ITEM_MIN) {
totalPay = (basePay + BONUS);
} else if (valueSold >= VALUE_MIN) {
totalPay = (basePay + BONUS);
} else {
totalPay = basePay;
}
System.out.println("this" + firstName + " " + lastName + " " + "will be paid" + totalPay + "for selling" + itemsSold + "items valued at $" + valueSold);

最新更新