public class LabWork {
private String yourStatus;
private int yourIncome;
private double tax;
public int calculateTax () {
if (yourStatus = "Married" && yourIncome <= 2000) {
tax = yourIncome/10;
}
else if (yourStatus = "Married" && yourIncome > 2000) {
tax = 3*yourIncome/20;
}
else if (yourStatus = "Single" && yourIncome <=2000) {
tax = 17*yourIncome/100;
}
else
tax = 22*yourIncome/100;
}
public double getTax () {
return tax;
}
}
this is my first code and I have a tester class to use this like:
import java.util.Scanner;
public class UseLab3Work {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("What is your status? ");
String yourStatus = keyboard.next();
System.out.println("What is your incomew? ");
int yourIncome = keyboard.nextInt();
}
}
However, in the first program, I'm getting an error like "String cannot be converted to boolean" at line 7,10 and 14. Then how should I use if with String? For example I have input in tester and when I write there Married, the program should calculate tax related to my String input.