My assignment is to create a calculator in java that tells the user his gross net pay and one of the requirements is asking if they're a union member or not. If they are, the code is supposed to multiply the gross by 5% and if not, nothing happens. With my current code, the gross is multiplied by 5% no matter if the user enters y or n.
System.out.print("Are you a union member (y or n)? ");
String answer = pd.nextLine();
if (answer.equals("y")) { //only applies if user is a member of the union
ud = gross * 0.05;
} else {
ud = 0;
}
union = pd.next();
Aucun commentaire:
Enregistrer un commentaire