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

Thread: PLEASE HELP ME JAVA MASTERS!!!

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PLEASE HELP ME JAVA MASTERS!!!

    SOURCE CODE:

    import java.util.Scanner;
    public class PayrollProgram {

    public static void main(String[] args) {
    Scanner xray = new Scanner(System.in);
    setEmpInfo re = new setEmpInfo ("", 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0.0, 0.0);

    while(true){
    System.out.println("Enter employee's name or stop to quit: ");
    re.name = xray.nextLine();
    if(re.name.toLowerCase().equals("stop")){
    System.exit(0);
    }
    System.out.println("\nNo. of Days Worked: ");
    re.days = xray.nextDouble();
    if(re.days <= 0){
    System.out.println("Enter No. of Days Worked again: ");
    re.days = xray.nextDouble();
    }
    System.out.println("Rate per Day: ");
    re.rpd = xray.nextDouble();
    if(re.rpd <= 0){
    System.out.println("Enter Rate per Day again: ");
    re.rpd = xray.nextDouble();
    }

    System.out.printf("\n");
    re.gross = re.days * re.rpd;
    System.out.printf("Employee's Name: %s", re.name);
    System.out.println("\nGross Salary");
    System.out.printf("Php %.2f\n\n", re.gross);

    re.lifeandretirementps = re.rpd * 22 * 0.09;
    System.out.println("Life and Retirement (Personal Share)");
    System.out.printf("Php %.2f\n", re.lifeandretirementps);

    re.lifeandretirementgs = re.rpd * 22 * 0.12;
    System.out.println("Life and Retirement (Government Share)");
    System.out.printf("Php %.2f\n\n", re.lifeandretirementgs);

    re.pagibigps = re.rpd * 22 * 0.02;
    System.out.println("PAG-IBIG (Personal Share)");
    System.out.printf("Php %.2f\n", re.pagibigps);

    re.pagibiggs = re.rpd * 22 * 0.02;
    System.out.println("PAG-IBIG (Goverment share)");
    System.out.printf("Php %.2f\n\n", re.pagibiggs);

    re.stateinsurance = re.rpd * 22 * 0.01;
    if(re.stateinsurance >= 100.00){
    System.out.println("State Insurance");
    System.out.printf("Php 100.00\n\n", re.stateinsurance);
    }
    else if(re.stateinsurance >= 90.00 && re.stateinsurance <= 99.99){
    System.out.println("State Insurance");
    System.out.printf("Php %.2f\n\n", re.stateinsurance);
    }

    re.stateinsurance = re.rpd * 22 * 0.01;
    if(re.stateinsurance >= 100.00){
    re.salarybracket = 125.00;
    re.philhealthps = re.salarybracket;
    System.out.println("PHILHEALTH (Personal share)");
    System.out.printf("Php %.2f\n", re.philhealthps);
    re.philhealthgs = re.salarybracket;
    System.out.println("PHILHEALTH (Goverment share)");
    System.out.printf("Php %.2f\n\n", re.philhealthgs);
    }
    else if(re.stateinsurance >= 90.00 || re.stateinsurance <= 99.99){
    re.salarybracket = 112.50;
    re.philhealthps = re.salarybracket;
    System.out.println("PHILHEALTH (Personal share)");
    System.out.printf("Php %.2f\n", re.philhealthps);
    re.philhealthgs = re.salarybracket;
    System.out.println("PHILHEALTH (Goverment share)");
    System.out.printf("Php %.2f\n\n", re.philhealthgs);
    }

    re.montuary = 100.00;
    System.out.println("Montuary");
    System.out.printf("Php %.2f\n\n", re.montuary);

    re.totaldeduction = re.lifeandretirementps + re.pagibigps + re.philhealthps + re.montuary;
    System.out.println("Total Deduction");
    System.out.printf("Php %.2f\n\n", re.totaldeduction);

    re.nettakehomepay = re.gross - re.totaldeduction;
    System.out.println("Net Take Home Pay");
    System.out.printf("Php %.2f\n\n", re.nettakehomepay);

    xray.nextLine();
    }
    }
    }

    class setEmpInfo extends PayrollProgram{
    String name;
    double days;
    double rpd;
    double gross;
    double lifeandretirementps;
    double lifeandretirementgs;
    double pagibigps;
    double pagibiggs;
    double philhealthps;
    double philhealthgs;
    double stateinsurance;
    double salarybracket;
    double montuary;
    double totaldeduction;
    double nettakehomepay;

    setEmpInfo(String xname,
    double xdays,
    double xrpd,
    double xgross,
    double xliferetirementps,
    double xliferetirementgs,
    double xpagibigps,
    double xpagibiggs,
    double xphilhealthps,
    double xphilhealthgs,
    double xstateinsurance,
    double xsalarybracket,
    double xmontuary,
    double xtotaldeduction,
    double xnettakehomepay) {

    name = xname;
    days = xdays;
    rpd = xrpd;
    gross = xgross;
    lifeandretirementps = xliferetirementps;
    lifeandretirementgs = xliferetirementgs;
    pagibigps = xpagibigps;
    pagibigps = xpagibiggs;
    philhealthps = xphilhealthps;
    philhealthps = xphilhealthgs;
    stateinsurance = xstateinsurance;
    salarybracket = xsalarybracket;
    montuary = xmontuary;
    totaldeduction = xtotaldeduction;
    nettakehomepay = xnettakehomepay;
    }

    public double calc(){
    return days * rpd;
    }

    OUTPUT:

    Enter employee's name or stop to quit:
    Mike Tyson

    No. of Days Worked:
    10
    Rate per Day:
    449.13

    Employee's Name: Mike Tyson
    Gross Salary
    Php 4491.30

    Life and Retirement (Personal Share)
    Php 889.28
    Life and Retirement (Government Share)
    Php 1185.70

    PAG-IBIG (Personal Share)
    Php 197.62
    PAG-IBIG (Goverment share)
    Php 197.62

    State Insurance
    Php 98.81

    PHILHEALTH (Personal share)
    Php 112.50
    PHILHEALTH (Goverment share)
    Php 112.50

    Montuary
    Php 100.00

    Total Deduction
    Php 1299.39

    Net Take Home Pay
    Php 3191.91

    MY PROBLEM:

    re.totaldeduction(1299.39) = re.lifeandretirementps(889.28) + re.pagibigps(197.62) + rephilhealthps(112.50) + re.montuary(100.00)

    Suppose to be the answer for Total Reduction is 1299.40 not 1299.39
    and Net Take Home Pay is 3191.90 not 3191.91. Please HELP ME JAVA MASTERS!!!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: PLEASE HELP ME JAVA MASTERS!!!

    Using double for money computations can lead to rounding errors.

    See: https://www.google.com/#q=problems+u...e+for+currency
    http://www.javapractices.com/topic/TopicAction.do?Id=13

    Please edit your post and wrap your code with code tags:
    [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.

  3. The Following User Says Thank You to Norm For This Useful Post:

    aprabhat (May 5th, 2014)

  4. #3
    Junior Member
    Join Date
    May 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP ME JAVA MASTERS!!!

    But sir if I'm going to input 482.81 as Rate per Day, the Total Deduction and Net Take Home Pay are totally correct even if I'm going to use calculator. Unlike with 449.13 as Rate per Day, the Total Deduction is 1299.39 instead of 1299.40. Only 0.01 is missing to complete the Total Deduction and affects the Net Take Home Pay. Please help me Java Master!

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: PLEASE HELP ME JAVA MASTERS!!!

    Did you read the links I posted? There are many solutions suggested there.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: PLEASE HELP ME JAVA MASTERS!!!

    Please post your code correctly and give your threads meaningful titles. For example, a more appropriate title for this thread might be "Help with rounding or math errors"