I'm trying to do a uni activity which involved writing the following program. I keep getting an error on line 27 where I've got else (employeetype == 2) {
, the error is as follows The left-hand side of an assignment must be a variable Syntax error, insert "AssignmentOperator Expression" to complete Assignment Syntax error, insert ";" to complete Statement
.
I'm new to java and don't really understand what I've done wrong here as the same assignment works in the if statement properly but not the else.
Could someone help me please?
import java.util.*;
public class TaskFive {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.println("Please type 1 if you are hourly rated or 2 if you are a salesperson.");
double employeetype = console.nextDouble();
double pay;
if (employeetype == 1) {
System.out.println("Please enter your hourly rate:");
double hourly = console.nextDouble();
System.out.println("Please enter the total hours you worked:");
double hoursworked = console.nextDouble();
if (hoursworked > 40) {
double overtimepay = hoursworked - 40;
pay = (overtimepay * (hourly * 1.5)) + (40 * hourly);
}
else {
pay = (hoursworked * hourly);
}}
else (employeetype == 2) {
System.out.println("Please enter your commission rate as a decimal:");
double comrate = console.nextInt();
System.out.println("Please enter your sales value:");
double sales = console.nextInt();
pay = 500 + (sales * comrate);
}
double tax = (pay*.3);
double netsalary = pay - tax;
System.out.println("Tax: " + tax);
System.out.println("Net Salary: " + netsalary);
}
}
Aucun commentaire:
Enregistrer un commentaire