Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

Write a program to compute an employee’s weekly pay and produce a pay slip showing name, gross pay (i.e. pay before deductions), deductions, and net pay (i.e., pay after deductions). The program should first prompt the user for: a) family (last) name b) given (first) name c) hourly rate of pay d) number of hours worked that week (any hours over 40 are paid at double the normal rate) e) a letter indicating the employee’s tax category

OpenStudy (anonymous):

A. no tax deduction B. tax is 10% of gross pay C. tax is 20% of gross pay D. tax is 29% of gross pay E. tax is 35% of gross pay f) either a ‘Y’ or an ‘N’ to indicate whether or not the employee wants $20 deducted from the weekly pay as a contribution to the United Way Charity.

OpenStudy (woodrow73):

What part are you having difficulty with?

OpenStudy (anonymous):

So, I am trying to set up my print statements, and I know that I will need a switch as well, but I am not sure how to integrate them. Also, I am not sure whether I need to declare variables before doing the print statements.

OpenStudy (anonymous):

Here is what I have done. } public static void main(String[]args) { System.out.printIn("What is your last name?"); String lastName = In.getString(); System.out.printIn("What is your first name?"); String fristName = In.getString(); System.out.printIn("What is your hourly rate of pay?"); double hourlyRate = In.getdouble(); System.out.printIn("How many hours did you work this week?"); double hoursWorked = In.getdouble(); } }

OpenStudy (woodrow73):

I've never seen the ln.get<dataType> method before - but it looks like a fine way to get user input. It's fine to declare the variables where you did - since their scope is in the main method. note: scope means how widely a variable can be used: ie; if you declare a variable like int x = 5 inside an if statement- x can only be used inside of that if statement. Now that you have the user input- it's about making the algorithm. to get weekly_pay_rate- you know to multiply hoursWorked by hourlyRate-- and weekly_pay_rate will be affected by 2 things- 1. taxes - and 2. if worked overtime It makes sense that we should put in any overtime money before we calculate taxes. this can be done doing: int hoursWorkedOverForty = 0; if(weekly_pay_rate > 40) { weekly_pay_rate = weekly_pay_rate * 40; hoursWorkedOverForty = weekly_pay_rate - 40; //finds extra hrs worked weekly_pay_rate = hoursWorked OverForty * (2 * hourlyRate); //above line will add extra hours at double the normal payrate } else { //this else statement will be if you work below or equal to 40 hours weekly_pay_rate = hoursWorked * hourlyRate; } --Ok, so now we have the weekly pay including extra hours- now to implement taxes

OpenStudy (woodrow73):

You can use the if-else-if statement, using ranges of the weekly pay rate, to determine which tax- bracket they're in. depending on which tax bracket they're in, you can deduct money from there.

OpenStudy (woodrow73):

And for whether they want to donate $20 to charity, we can ask that after all that code is written- I'm good with string manipulation, and the Scanner syntax & JOptionPane syntax if you would like me to teach you

OpenStudy (anonymous):

so after I did the the if-else-if statement using the ranges of the weekly pay rate, would I be using more if statements to deduct money?

OpenStudy (anonymous):

and the charity part of the code?

OpenStudy (woodrow73):

you can ask if the user wants to donate $20 or not- and you can save that answer to a string- then using the charAt method, you can see if the first character is = 'N' or 'Y'

OpenStudy (anonymous):

ok let me try that first

OpenStudy (woodrow73):

wait- is the tax bracket determined by how much you get paid, or is it also determined by the user input?

OpenStudy (anonymous):

the user input, so for example if the user inputs A, the tax bracket will be 20%

OpenStudy (woodrow73):

char charVariable = <stringVariable>.charAt(0); this syntax will put the first character of stringVariable into the char variable called charVariable

OpenStudy (woodrow73):

ah- then forget my if-else-if , I was assuming that the bracket was a function of how much you made. A switch statement does work best lol. anyway I gtg- I'll check in later.

OpenStudy (anonymous):

ok thanks

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!