A security man is paid at the hourly rate( R ) for the first 40 hours of work in a week. There after he his paid at 1.25 times the hourly rate (R) for the next 16 hours and 1.5 times the hourly rate ( R) for further hours of work in the week. Taking the number of hours (H) and rate per hour( R) as input, the weekly wage (W) us to be calculated. Write a program to calculate weekly wages and display it. Write an algorithm/Java program to calculate and print the rate(R), hours(H) and wages(W).
@Nnesha @Zale101 @nincompoop @Whitemonsterbunny17
@AlexandervonHumboldt2 @Agl202
@ganeshie8
That's fairly simple all you would have to do is check if the hours are more than 40 of it is then check if it is more than 16 hours and calculate it like that so for example let's say I worked for 58 hours in that week. So 40 hours would be accounted for at normal pay then I worked 18 hours more so for the next 16 I get paid 1.25 more than what I get paid hourly and since there is still 2 hours left you must multiply 1.50 by the hourly pay and add the sum of all of that and that should give you a total. For the record im trying to help without giving you the syntax. If you have any sort of code post it here and I'll gladly take a look at it and point out mistakes or what you should add if there is anything I do notice. If you want me to clarify anything please do ask.
class Wages{ public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please enter hourly rate: "); R = input.nextDouble(); System.out.println("Please enter number of hours worked: "); H= input.nextInt(); if ( 0 < = H && H<= 40) { W = R*H; } else if ( 40< H && H <= 56 { W = 1.25*R * H } else if (H > 56) { W = 1.5*R*H; System.out.println("Total Wages are " + W); } } @kva1992
???
Your if statement is wrong. It should be. if ( H>=0 && H<= 40) { W = R*H; } else if ( H >=40 && H <= 56 { W=40*R; W=W+((1.25*R)(H-40)); } else if (H > 56) { W = 40*R; W = W + ((1.25*R)(16)); W = W + ((1.50*R)(H-56));
That should fix your issue let me know of you want me to explain.
System.out.println("Total Wages are " + W); Add that after your if statement.
like how can u show me plsss
What am I showing you exactly?
is this right ???? public class Wages{ public static void main(String[] args) { double a,b,c, R, W=0; int H; Scanner input = new Scanner(System.in); System.out.println("Please enter hourly rate: "); R = input.nextDouble(); System.out.println("Please enter number of hours worked: "); H = input.nextInt(); if (H >= 0 && H <= 40) { W = R * H; } else if (H > 40 && H <= 56) { W = R*40 + 1.25 * R * (H-40); } else if (H > 56) { W = R*40 + 1.25 * R * 16 + 1.5 * R * (H-56); } System.out.println("Total Wages are " + W); }
@kva1992
CAN u show me the code in algorithm plsss @kva1992
I would personally separate the calculation just so the program doesn't Compute from left to right and does it properly you could use the ABC variables at the top of the page.
But essentially you got it
ya can u show me in pseudocode form
I can't exactly give you pseudocode right now I'm on my phone won't have a PC for another week or so
Just type exactly what your program is doing
Input both user driven and application driven and outputs and calculation the things that happen in the back end in order
And that will be your pseudocode
Hopefully that answered all your questions
thx anyways
No problem
Join our real-time social learning platform and learn together with your friends!