1. Member
Join Date
Dec 2008
Posts
1
Rep Power
0

## Need Help

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.

2. ## hhhmmm...

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)

Luck,
CJSL

3. One way to solve this assignment is to use a conversion array. An example of this is here:
Java Code:
```import java.util.Scanner;

class HomeworkWeeklySalary
{

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();
scanner.nextLine();

String result = calcSalary(hours);
System.out.println("The result is: " + result);
scanner.close();
}

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);
return result;
}

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
};

}```
If you don't understand this code, just run it a few times and its use will become obvious.

Good luck and hope this helps.
Last edited by Fubarable; 12-27-2008 at 02:53 AM.

4. Furball... you're incorrigible

CJSL

5. Originally Posted by CJSLMAN
Furball... you're incorrigible
CJSL
And I thought it was a decent solution to his homework question. I'm darn proud of that code.

6. ## Indeed it is...

I'm sure you are proud of it... keep up the good work !!!

CJSL

7. Originally Posted by CJSLMAN
Furball... you're incorrigible

CJSL
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. :)

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.

8. You didn't run my code, did you Eranga? ;)

9. 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.

10. but it does point him in a direction if he runs it. trust me, it does.

11. Originally Posted by Fubarable
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. :)

12. ## hhhmmm...

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.

CJSL

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•