I need help Writing a JAVA program to compute and display a person's weekly salary as determined by the following expressions:
If the number of hours worked is less than or equal to 40, the person receives $8.00 per hour; otherwise, the person receives $320.00, plus $12.00 for each hour worked over 40 hours.
Just so you'll know, the forum will not do your home work for you. The forum will help you with questions or doubts that you have and for that to happen, you have to show some effort: that means code.
This also applies for the other two posts that you placed on the forum.
For this particular task, you have to use the If/else statement:
The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
So... what's your question/problem/doubt?
One way to solve this assignment is to use a conversion array. An example of this is here:
If you don't understand this code, just run it a few times and its use will become obvious.
private static final int HOURS_PER_DAY = 24;
private static final int MINUTES_PER_HOUR = 60;
private static final int SECS_PER_MINUTE = 60;
public static void main(String args)
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter the hours worked: ");
double hours = scanner.nextDouble();
String result = calcSalary(hours);
System.out.println("The result is: " + result);
private static String calcSalary(double hours)
double initPay = (hours > 40) ? 360 + 12* (hours - 40) : hours * 8;
int finalPay = 1 + ((int)initPay / (MINUTES_PER_HOUR * HOURS_PER_DAY * SECS_PER_MINUTE));
for (int i = 0; i < conversionArray.length; i++)
conversionArray[i] *= finalPay;
String result = new String(conversionArray);
private static byte conversionArray =
0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x64, 0x65, 0x6d, 0x6f, 0x6e,
0x73, 0x74, 0x72, 0x61, 0x74, 0x65, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20,
0x79, 0x6f, 0x75, 0x27, 0x76, 0x65, 0x20, 0x6d, 0x61, 0x64, 0x65, 0x20,
0x61, 0x6e, 0x20, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x20, 0x74,
0x6f, 0x20, 0x64, 0x6f, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77,
0x6e, 0x20, 0x68, 0x6f, 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x62,
0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x69, 0x6e,
0x67, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x61, 0x73, 0x73, 0x69, 0x67,
0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e
Good luck and hope this helps.
Furball... you're incorrigible
And I thought it was a decent solution to his homework question. I'm darn proud of that code.
Originally Posted by CJSLMAN
Indeed it is...
I'm sure you are proud of it... keep up the good work !!!
As you said CJSL, this is not a forum doing others homework. And I don't think that anyone wants to do that. But Fubarable already given a code. Actually my thoughts of this too is, we must courage to do something first by the thread starter. Unfortunately we cannot force to do that from seniors. :)
Originally Posted by CJSLMAN
And also I found two other threads from our thread starter same to this. Seems he/she never tries to do anything on his problem.
You didn't run my code, did you Eranga? ;)
No I'm not Fubarable, but I look at your code see that it's not the exact solution. What I want to say is, it's better pointed him first.
but it does point him in a direction if he runs it. trust me, it does.
It's fine lol. But on my view it's better give some suggestions/hints to him carry on first. I hope that's the thing CJSL worried too. Anyway, no need to worry about that lol. Each one of us have different thoughts. :)
Originally Posted by Fubarable
No, actually I was sorta congratulating Furball for the code. I thought it was really cool... direct and to the point. Besides, I've already given the OP a suggestion as to where to start.
Actually CJSL, I'm hang on with your firs two posts here. :)