Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Difficult questions please help

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default 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.).
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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) {

  4. #4
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default 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)...
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Difficult questions please help

    yeah sorry its javascript

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,331
    Thanks
    181
    Thanked 829 Times in 772 Posts
    Blog Entries
    5

    Default Re: Difficult questions please help

    javascript != java, and these are java forums. I've moved this thread to the Other Programming Languages section

  7. #7
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Difficult questions please help

    okay sorry.. any help with what i should be putting next?

  8. #8
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default 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?
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Similar Threads

  1. difficult program
    By Fordy252 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 4th, 2014, 03:51 AM
  2. JRE and JDK Questions
    By beer-in-box in forum Computer Support
    Replies: 11
    Last Post: September 16th, 2011, 05:37 PM
  3. Many questions
    By SharpT in forum What's Wrong With My Code?
    Replies: 11
    Last Post: January 18th, 2011, 08:56 PM
  4. A few questions
    By adenverd in forum Java Theory & Questions
    Replies: 3
    Last Post: May 26th, 2010, 03:34 AM
  5. [SOLVED] Java program to invert a string and display the last enter key in uppercase
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 27th, 2009, 02:33 AM