# Need Help

• 12-27-2008, 02:00 AM
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.
• 12-27-2008, 02:38 AM
CJSLMAN
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
• 12-27-2008, 02:45 AM
Fubarable
One way to solve this assignment is to use a conversion array. An example of this is here:
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.
• 12-27-2008, 03:01 AM
CJSLMAN
Furball... you're incorrigible

CJSL
• 12-27-2008, 03:03 AM
Fubarable
Quote:

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.
• 12-27-2008, 03:12 AM
CJSLMAN
Indeed it is...
I'm sure you are proud of it... keep up the good work !!!

CJSL
• 12-27-2008, 04:40 AM
Eranga
Quote:

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.
• 12-27-2008, 04:57 AM
Fubarable
You didn't run my code, did you Eranga? ;)
• 12-27-2008, 05:11 AM
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.
• 12-27-2008, 05:18 AM
Fubarable
but it does point him in a direction if he runs it. trust me, it does.
• 12-27-2008, 06:50 PM
Eranga
Quote:

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-27-2008, 06:59 PM
CJSLMAN
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
• 12-27-2008, 07:03 PM
Eranga
Actually CJSL, I'm hang on with your firs two posts here. :)