我正在尝试做一个简单的计算。我不知道如何在最后一个 if-else 语句中减去“double admissionPrice”。
它指向减法符号给我这个错误消息: operator - cannot be applied to java.lang.String,double
请帮忙。谢谢。
import java.text.*;
import java.util.Scanner;
class IMC {
public static void main(String[] args) {
int numEmployees = 0;
double costPerAttendee = 0.00;
int employeeDiscount;
double admissionPrice = 0.00;
Scanner keyboard = new Scanner (System.in);
System.out.print("Enter amount of employees attending: ");
numEmployees = keyboard.nextInt();
System.out.print("Have any employees attended previously? \n For: YES=1 or NO=2"
);
employeeDiscount = keyboard.nextInt();
if (numEmployees == 1) { admissionPrice = 695.00;
} else if (numEmployees == 2 || numEmployees == 3 ||numEmployees == 4) { admissionPrice = 545.00;
} else if (numEmployees >= 5 ||numEmployees >= 6 ||numEmployees >= 7 ||numEmployees >= 8){ admissionPrice = 480.00;
} else if (numEmployees >= 9) { admissionPrice = 395.00;
}
System.out.print("The cost per attendee is: " + admissionPrice );
if (employeeDiscount == 1){
System.out.print("Total price after discount (15%) is : " + admissionPrice - (admissionPrice * 0.15) );
} else if (employeeDiscount == 2) {
System.out.print("No discount. Total price is still: " + admissionPrice);
}
}
}