On my class side I cannot seem to get netPay to calculate and am also having problems with finding insDeduct. On the demo side I have you choose between S - Single and M - Married.

Any help would be greatly appreciated.

public class ChapterFiveClass
{

    // Declare some fields

    private String name, status;
    private double hours, rop, grossPay, fedTax, stateTax, ficaTax, insDeduct, netPay;

    final double FED_TAX_RATE = .10;
    final double STATE_TAX_RATE = .08;
    final double FICA_TAX_RATE = .0625;


    // Constructor

    public ChapterFiveClass(String aName, double theHours, char theStatus, double theRop)
    {

        name = aName;
        hours = theHours;
        status = theStatus;
        rop = theRop;

    }

    // Getters and Setters

    public String getName()
        {

            return name;

        }

    public double getHours()
        {

            return hours;

        }

    public String getStatus()
        {

            return status;

        }

    public double getRop()
        {
            return rop;

        }

    public void setHours(double theHours)
        {

            hours = theHours;

        }

    public void setStatus (char theStatus)
        {

            status = theStatus;

        }

    public void setRate (double theRop)
        {

            rop = theRop;

        }

    // Calculation Methods

    public double calcgrossPay()
       {

           if (hours <= 40)

                   grossPay = hours * rop;

           else

                   grossPay = (1.5 * rop) * (hours-40) + (rop * 40);

           return grossPay;
        }


    public double calcfedTax()
    {
        double fedTax;
        fedTax = (grossPay * FED_TAX_RATE);
        return fedTax;
    }

    public double calcstateTax()
    {
        double stateTax;
        stateTax = (grossPay * STATE_TAX_RATE);
        return stateTax;
    }

    public double calcficaTax()
    {
        double ficaTax;
        ficaTax = (grossPay * FICA_TAX_RATE);
        return ficaTax;
    }

    public double calcinsDeduct()
    {
        double insDeduct;

        if (statusStr.charAt(0) == 'S');

            insDeduct = 50.00;

        else if (statusStr.charAt(0) == 'M');

            insDeduct = 100.00;

        return insDeduct;
    }


    public double calcnetPay()
    {

        netPay = (grossPay - fedTax - stateTax - ficaTax - insDeduct);
        return netPay;
    }

 }
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class ChapterFiveDemo
{
        public static void main (String [] args)
        {

        // Declare variables

        String name, hoursStr, ropStr, empNumStr, statusStr, output = "";
        char status;
        int empNum = 1, x = 1;
        double hours, rop;

        // Validate number of employees to process

        empNumStr = JOptionPane.showInputDialog("Please enter number of employees to process between 1 - 3");

        // Cast

        empNum = Integer.parseInt(empNumStr);

        // While loop

            while (empNum >= 1 && empNum <=3)
            { // open while

                while (x <= empNum)
                { // open while loop 2

                name = JOptionPane.showInputDialog("Please enter employee name");

                hoursStr = JOptionPane.showInputDialog("Please enter the number of hours worked");

                statusStr = JOptionPane.showInputDialog("Please enter S - Single or M - Married");

                ropStr = JOptionPane.showInputDialog("Please enter the employee's rate of pay");


                // Cast Data

                hours = Double.parseDouble(hoursStr);

                rop = Double.parseDouble(ropStr);


                // Instantiate Object

                ChapterFiveClass employee = new ChapterFiveClass (name, hours, status, rop);


                // Creat object to format data

                DecimalFormat dollars = new DecimalFormat("$###.00");

                // Concatanation of output

                output = output + ("\n" + employee.getName() + "\n Rate of Pay: "
                                        + dollars.format(employee.getRop())+"\n Hours worked: "
                                        + employee.getHours()) + "\n Gross Pay: "
                                        + dollars.format(employee.calcgrossPay()) + "\n Insurance Deduction: "
                                        + dollars.format(employee.calcinsDeduct()) + "\n FICA Tax Deduction: "
                                        + dollars.format(employee.calcficaTax()) + "\n State Tax Deduction: "
                                        + dollars.format(employee.calcstateTax()) + "\n Federal Tax Deduction: "
                                        + dollars.format(employee.calcfedTax()) + "\n Net Pay: "
                                        + dollars.format(employee.calcnetPay());
                x++;

                } // close the while loop

                JOptionPane.showMessageDialog(null, "The employee list is: " + output);



                //cast

                empNum = Integer.parseInt(empNumStr);


            } // close while loop

            JOptionPane.showMessageDialog(null, "You've exited the program because of an invalid number.");



}
}

what exactly is the code that doesn't run? can you be a bit more specific about that?
can you be specific about what input you're giving in the application?

I've just taken a closer look at your code ....
have you actually been able to compile that code?
kind of doubt it, you're using variables you're not declaring.
also, remove the ';' from behind your if and else if statements.

Hello there,

I've done some adjustments which in my opinion make the code easier to update later.
Try to keep methods like setName or getName because It'll make your life easier in some time in the future.
When you have some free time take a look at Java Code Conventions.
I don't know exactly what you want to do with this class, but one thing I can tell you, It can now be easily improved.

Hope it helped

public class ChapterFiveClass {

  public static void main(String [] args) {
    ChapterFiveClass c = new ChapterFiveClass("John", 51, 'M', 20);

    System.out.println("Name:\t\t" + c.getName());
    System.out.println("Hours:\t\t" + c.getHours());
    System.out.println("Status:\t\t" + c.getStatus());
    System.out.println("Rop:\t\t" + c.getRop());
    System.out.println("GrossPay\t" + c.getGrossPay());
    System.out.println("FedTax:\t\t" + c.getFedTax());
    System.out.println("StateTax\t" + c.getStateTax());
    System.out.println("FicaTax\t\t" + c.getFicaTax());
    System.out.println("InsDeduct\t" + c.getInsDeduct());
    System.out.println("NetPay\t\t" + c.getNetPay());
  }
    
  // Declare some fields
  private String name;
  private char status;
  private double hours, rop, grossPay, fedTax, stateTax, ficaTax, insDeduct, netPay;

  final double FED_TAX_RATE = .10;
  final double STATE_TAX_RATE = .08;
  final double FICA_TAX_RATE = .0625;

  // Constructor
  public ChapterFiveClass(String cName, double cHours, char cStatus, double cRop) {
    this.setName(cName);
    this.setHours(cHours);
    this.setStatus(cStatus);
    this.setRop(cRop);
    
    this.setGrossPay();
    this.setFedTax();
    this.setStateTax();
    this.setFicaTax();
    this.setInsDeduct();
    this.setNetPay();
  }

  // Getters and Setters
  public void setName(String mName) {
    if (mName != null) {
      this.name = mName;
    } else {
      System.out.println("Please a valid name.");
    }
  }
  public String getName() {
    return this.name;
  }

  public void setHours(double mHours) {
    if ((mHours > 0) && (mHours < 100)) {
      this.hours = mHours;
    } else {
      this.hours = 0;
      System.out.println("Please add a valid amount of Hours being > 0 and < 100.");
    }
  }
  public double getHours() {
    return this.hours;
  }

  public void setStatus(char mStatus) {
    if ((mStatus == 'M') || (mStatus == 'm') || (mStatus == 'S') || (mStatus == 's')) {
      this.status = mStatus;
    } else {
      System.out.println("Please add a valid status, M for Married or S for Single.");
    }
  }
  public char getStatus() {
    return this.status;
  }

  public void setRop(double mRop) {
    this.rop = mRop;
  }
  public double getRop() {
    return this.rop;
  }

  // Calculation Methods
  public void setGrossPay() {
    if (hours <= 40) {
      this.grossPay = this.getHours() * this.getRop();
    } else {
      this.grossPay = (1.5 * this.getRop()) * (this.getHours()-40) + (this.getRop() * 40);
    }
  }
  public double getGrossPay() {
    return this.grossPay;
  }

  public void setFedTax() {
    this.fedTax = this.getGrossPay() * FED_TAX_RATE;
  }
  public double getFedTax() {
    return this.fedTax;
  }

  public void setStateTax() {
    this.stateTax = this.getGrossPay() * STATE_TAX_RATE;
  }
  public double getStateTax() {
    return this.stateTax;
  }

  public void setFicaTax() {
    this.ficaTax = this.getGrossPay() * FICA_TAX_RATE;
  }
  public double getFicaTax() {
    return this.ficaTax;
  }

  public void setInsDeduct() {
    if ((this.getStatus() == 'S') || (this.getStatus() == 's')) {
      this.insDeduct = 50;
    } else if ((this.getStatus() == 'M') || (this.getStatus() == 'm')) {
      this.insDeduct = 100;
    } else {
      System.out.println("Please add a valid status.");
    }
  }
  public double getInsDeduct() {
   return this.insDeduct;
  }

  public void setNetPay() {
    this.netPay = this.getGrossPay() - this.getFedTax() - this.getStateTax() - this.getFicaTax() - this.getInsDeduct();
  }
  public double getNetPay() {
    return this.netPay;
  }

}
commented: Handing out answers with no explanation doesn't help. -4

I assume the point was the OP had trouble coming this far, so just handing code without seeing whether or not he can find the problems I've mentioned before won't help him learn, it might help him passing a course, but then again, so does cheating.

Sorry about that... Didn't realise that I wasn't helping when I was trying to help.
I'll be more carefull in the future.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.