Answer:
// Payroll.java
public class Payroll
{
int numOfDependents;
double salary;
double salaryToHome;
double Federal_Tax,TAX_RATE,Depen_tax;
Payroll(double salry,int nod)
{
numOfDependents=nod;
salary=salry;
Federal_Tax=6.5;
TAX_RATE=28.0;
Depen_tax=2.5;
}
double getTAX_RATE()
{
return TAX_RATE*salary/100;
}
double Federal_Tax()
{
return Federal_Tax*salary/100;
}
double getDepenAmount()
{
return numOfDependents*(Depen_tax*salary/100);
}
double getTakeHomeSalary()
{
return salary+getDepenAmount()-(getTAX_RATE()+Federal_Tax());
}
void printOutput()
{
System.out.print("\nState Tax: $"+getTAX_RATE());
System.out.print("\nFederal Tax: $"+Federal_Tax());
System.out.print("\nDependents: $"+getDepenAmount());
System.out.print("\nSalary: $"+salary);
System.out.println("\nTake Home Pay: $"+getTakeHomeSalary());
}
public static void main(String args[])
{
Payroll obj=new Payroll(1250,2);
obj.printOutput();
}
}
// ModifiedPayroll.java
import java.util.Scanner;
public class ModifiedPayroll
{
int numOfDependents;
double salary;
double salaryToHome;
double Federal_Tax,TAX_RATE,Depen_tax;
ModifiedPayroll(double salry,int nod)
{
//initialise variables
numOfDependents=nod;
salary=salry;
Federal_Tax=6.5;
TAX_RATE=28.0;
Depen_tax=2.5;
}
double getTAX_RATE()
{
return TAX_RATE*salary/100;
}
double Federal_Tax()
{
return Federal_Tax*salary/100;
}
double getDepenAmount()
{
return numOfDependents*(Depen_tax*salary/100);
}
double getTakeHomeSalary()
{
return salary+getDepenAmount()-(getTAX_RATE()+Federal_Tax());
}
void printOutput()
{
System.out.print("\nState Tax: $"+getTAX_RATE());
System.out.print("\nFederal Tax: $"+Federal_Tax());
System.out.print("\nDependents: $"+getDepenAmount());
System.out.print("\nSalary: $"+salary);
System.out.println("\nTake Home Pay: $"+getTakeHomeSalary());
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter Salary: $");
double salary=sc.nextDouble();
System.out.print("\nEnter number Of Dependents:$");
int nob=sc.nextInt();
ModifiedPayroll obj=new ModifiedPayroll(salary,nob);
obj.printOutput();
}
}
Explanation/Output:
// For Payroll.java
State Tax: $350.0
Federal Tax: $81.25
Dependents: $62.5
Salary: $1250.0
Take Home Pay: $881.25
// For ModifiedPayroll.java
Enter Salary:$1550.0
Enter number of Dependents:$3
State Tax: $434.0
Federal Tax: $100.75
Dependents: $116.25
Salary: $1550.0
Take Home Pay: $1131.5