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 6 of 6

Thread: Help Needed

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

    Default Help Needed

    IF Statements

    Write the program logic that will compute the paycheck of an employee. This is as much an exercise in designing your logic as much as a programming exercise in the grammar and syntax.

    Your program's logic will perform a user to perform the following:
    1. Enter the employee's LAST Name
    2. Enter the employee's FIRST Name
    3. Enter the employee's ID Number
    4. Enter the employee's Total Hours Worked up to a maximum of 60 hours
    5. Enter the employee's Pay Per Hour. The Pay per hour cannot be more than $100.00 per hour. It cannot be less than the minimum wage (i.e. $8.50 per hour). Detect any erroneous pay rate and set it to a default. If less than the minimum hourly wage, set to the minimum hourly wage. If greater than the maximum rate then set that employee to the maximum rate. Display an appropriate “error message” telling that data entry clerk what they did.
    6. Federal tax rate and State tax rate range from zero to 40%. State and Federal tax rates cannot exceed a combined 80%.
    7. Calculations include:
    a) Compute the Regular Pay (any hours up to 40 hours) Regular Hours X Pay Per Hour
    b) Compute the Overtime Pay if ANY (hours OVER 40 hours)
    Overtime Hours X Pay Per Hour X 1.25 ("time and a quarter" for overtime)
    c) Compute Gross Pay
    Regular Pay + Overtime Pay (if NO overtime then Overtime Pay is zero)
    d) Compute Federal Taxes Withheld (assume 20% rate, i.e. 0.2) Gross Pay X Federal Tax Rate
    e) Compute State Taxes Withheld (assume 5% rate, i.e. 0.05) Gross Pay X State Tax Rate
    f) Compute Net Pay (Gross Pay - Federal Taxes Withheld - State Taxes Withheld)

    Output the employee's LAST Name, FIRST Name, ID Number, Total Hours, Regular Hours, Overtime Hours, if any (if NO overtime hours then don't print it), Gross Pay, Regular Pay, Overtime Pay, if any (if NO overtime hours then don't print it), Federal Taxes Withheld, State Taxes Withheld, Net Pay. Output format, I leave to your imagination (i.e. some sort of if statement?).


    output where i have to show last name , first name , id, total hours, regular hours
    then regular hour and over time
    then gross pay then federal tax and state tax . i need the constant declare


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,192
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Help Needed

    Do you have any specific questions about your assignment?
    Please post your code and any questions about problems you are having.

    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Help Needed

    // Assignment 2
    import java.io.*;

    public class payment
    {
    public static void main(String args[]) throws IOException
    {
    BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
    System.out.println("Enter your last name: ");
    String last = input.readLine();
    System.out.println("Enter your first name: ");
    String first = input.readLine();
    System.out.println("Enter your ID: ");
    String ID = input.readLine();
    System.out.println("Enter your total work hrs: ");
    Double hr = Double.parseDouble(input.readLine());
    if( hr > 60)
    {
    System.out.println("Total Hours can not be more than 60hrs");
    System.out.println("Enter your total work hrs: ");
    hr = Double.parseDouble(input.readLine());
    }
    System.out.println("Enter pay per hrs rate: ");
    Double rate = Double.parseDouble(input.readLine());
    if(rate>100)
    {
    System.out.println("Rate per hr. not correct");
    rate = 100.00;
    }
    if(rate<8.5)
    {
    System.out.println("Rate per hr. not correct");
    rate = 8.5;
    }
    System.out.println("Enter Federal tax(0% - 40%): ");
    Double fd = Double.parseDouble(input.readLine());
    System.out.println("Enter State tax (0% - 40%): ");
    Double st = Double.parseDouble(input.readLine());
    if((fd+st)>80)
    System.out.println("Wrong tax rate enterd");
    Double rpay; Double otime=0.0;
    if(hr<=40)
    rpay=hr*rate;
    else
    {
    rpay= 40*rate; otime= (hr-40) * rate * 1.25;
    }

    Double totalworkhours = hr+otime;
    Double gpay= rpay+otime;
    Double ftw= gpay*fd/100;
    Double stw=gpay*st/100;
    Double netpay= gpay-ftw-stw;



    System.out.println("Last Name"+ last +"First Name"+ first);
    System.out.println("ID number: "+ ID);
    System.out.println("Total Hours Worked " + totalworkhours);
    System.out.println("Regular time: "+ (hr-otime));
    System.out.println("Over Time: "+ otime);
    System.out.println(" Federal tax: "+ ftw);
    System.out.println(" State tax : "+ stw);
    System.out.println("Net Pay: "+ netpay);


    }
    }
    this is code but its not working

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,192
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Help Needed

    its not working
    Please explain.
    If there are error messages, please copy the full text and paste it here.
    If the output is wrong, copy the output and paste it here and add some comments saying what is wrong with the output and show what the output should be.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Help Needed

    Last Name johalFirst Name navi
    ID number: 123de
    Total Hours Worked 636.0
    Regular time: -524.0
    Over Time: 580.0
    Federal tax: 348.0
    State tax : 174.0
    Net Pay: 1218.0
    like when more than 40 then it gaves me a negative answer for the regular time how can i fix it

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,192
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Help Needed

    Regular time: "+ (hr-otime));
    What are the expected and actual values of hr and otime?
    If otime > hr, then the result will be a negative number.

    Look at where each of those variables get their values and see why they are a problem.

    Define what is in the hr variable
    and in the otime variable.
    Are they compatible?

    when more than 40 then it gaves me a negative answer for the regular time
    What should the answer be?

    Your unformatted code is hard to read and understand. Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Grails Developer Needed - URGENTLY NEEDED *WORK FROM HOME*
    By IngeniumR in forum Paid Java Projects
    Replies: 0
    Last Post: February 5th, 2013, 06:19 AM
  2. help needed!!
    By arvindbis in forum Web Frameworks
    Replies: 0
    Last Post: October 9th, 2011, 10:43 AM
  3. help!!!! needed!! please
    By isuckatprogramming in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 22nd, 2011, 03:20 PM
  4. help needed ,,, please
    By dpes in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 7th, 2010, 09:03 AM
  5. [SOLVED] A little help needed..
    By JavaStudent87 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 22nd, 2010, 05:54 PM