lundi 20 septembre 2021

I can't figure out why my if statement won't listen to the user's input [duplicate]

I have an asssignment that is supposed to calculate a workers net pay and one of the requirements is to ask the user if they work for the union or not and if they say "y" you're supposed to multiply their gross pay by 0.05 but if they're not, there are just no dues to be paid. I can get my statement to either do the math or not but for some reason it's not listening to the user's input...

System.out.print("Enter name: ");
name = pd.next();
System.out.print("Enter hours worked: ");
hours = pd.nextDouble(); 
System.out.print("Enter hourly pay rate: ");
rate = pd.nextDouble();
gross = hours * rate;
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 = gross * 0.00;
 
    }
       
union = pd.next();
//System.out.print("What percentage do you wand to withhold for your medical savings account? ");
mw = pd.nextDouble();
mw = gross * (mw/100);

Aucun commentaire:

Enregistrer un commentaire