Difficult questions please help
i can't do these last two questions for college and i would really appreciate some help:
9. SlowDrivers Inc. pay their workers a basic wage of £4.60 an hour. If an employee works over 40
hours a week they receive £5.60 an hour for every hour of overtime they work. Workers can work a
maximum of 80 hours a week.**
Create a function called calculateWage. The function should prompt the user to enter the number
of hours they have worked and assign this to a variable called hours. Create two variables
basicWage and overTime which will store the rates of pay. Complete the rest of the code for this
function which will calculate the user’s wage based on the number of hours that they have worked
in that week.**
If a user has entered a correct number of hours, then the alert box should say “Your basic wage is
£” followed by the correct output. If the user enters an incorrect number of hours, then the alert
box should say “Please check the number of hours that you have worked.” [14]
Hint: use the built in method of .toFixed(2) to ensure the final wage is displayed to two
decimal places.
* *
10. HighPrice Gas Ltd. charge their customers for gas as follows
No of Units used Price(£)
0 to 100 £1 per unit
101 to 1000 £1 per unit, plus 50p for each additional unit over 500
Over 1000 £3 per unit, plus 5p for each additional unit over 1000
Create a function called gasReading which takes a parameter called units. When run, the function
should pass in the number of units used by a customer and calculate the price, which is stored in a
variable called cost. The function should then return the cost as part of an alert box, with the text
“Your gas bill is: ” and then display the cost of the gas used. Call this function, passing the value
1200 as a parameter. [12]
Thank you
Re: Difficult questions please help
I'm glad to help you, but know that no one here is going to hand you the answer.
Now, have you started any code so far? If so, could you post it please? (Be sure to use the correct syntax: [highlight=Java]//your code here[/highlight]
If you don't have code, I suggest creating on a piece of paper a model representing the structure of your program (paths of execution based on the hours worked, input validation ideas, etc.).
Re: Difficult questions please help
for now for question 9 i have:
function calculateWage() {
var basicWage = 4.60;
var overTime = 5.60;
var hours = prompt("enter hours worked");
if (hours > 40) {
Re: Difficult questions please help
Are you doing this in Java, or another coding language? The code you have posted above does not follow Java syntax (in fact, it looks more like Flash or JavaScript)...
Re: Difficult questions please help
yeah sorry its javascript
Re: Difficult questions please help
javascript != java, and these are java forums. I've moved this thread to the Other Programming Languages section
Re: Difficult questions please help
okay sorry.. any help with what i should be putting next?
Re: Difficult questions please help
I cannot directly help you with the code, since I know little JavaScript (but perhaps this'll be better for both of us...).
So, if the hours are greater than 40, you need to account for normal pay and overtime pay (which is only applied to hours over 40). So, hours 1-40 must be multiplied by the normal pay rate, and hours 41-x (however many were worked) need to be multiplied by the overtime rate.
Does this help?