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.");
}
}