4
Answers

method edit required ? its not working ?

SUNIL GUTTA

SUNIL GUTTA

11y
832
1
Hi small help required ... 

I am having problems getting the healthcare costs method to work. I am posting the assignment description. Then I will give the code that I have so far...




Inputs:


1) Name


2) Hours worked


3) Rate of Pay ($ / hour)


4) Marital Status (Married, Single)


5) # of Dependents


6) Healthcare (Yes or No)


7) Keeps asking for additional inputs and creating the outputs until a name of X is given.


Outputs:


1) Gross pay (Hours over 40 are paid at time and Ã?½)


2) Taxable Pay (Gross � Medical Deduction, if selected, from table below)
Federal Tax








Additional Requirements:


1)Use functions for major tasks


a.Calculate Gross Pay


b.Calculate Health Deductions


c.Calculate Tax


d.Calculate Net Pay


2)Other than constants, do NOT use global variables
(e.g You need to pass variable between functions through the argument list).


3)Comment each function and variable and major sections of code.


4)Submitting a program that does not compile is an automatic 20 point deduction.


Tax Calculation Pseudocode


The following is one possible pseudocode for calculating the tax. There are many ways to implement this code,any that work are acceptable.


Assume that variable GrossPay is the calculated total pay for individual. All the constants are from the table on the previous page:
If married
TaxablePay = GrossPay � 150 � 70.0 * NumberDependents
if healthcare
TaxablePay = TaxablePay � 100
if TaxablePay > 800
Tax = (TaxablePay - 800) * .35 + (800 - 500) * .25 + (500 - 200) * .15 +200 * .10


Here is what I have so far..
public static void main(String[] args) {
String name; // hold name input
double grossPay; // To hold gross pay
double taxablePay; // To hold taxable pay
double federalTax; // To hold federal tax
double net;

Scanner keyboard = new Scanner(System.in);
System.out.print("What is your name? ");
name = keyboard.nextLine();

// get the gross pay.
grossPay = getGross();

// get the taxable pay.
taxablePay = getTaxablePay(grossPay);

// get the federal tax.
federalTax = getFedTax(grossPay, taxablePay);

// get the net pay.
net = getNetPay(taxablePay, federalTax);

// display results
displayResults(grossPay, federalTax, taxablePay, net, name);

// stop program

}

public static double getGross()
{

double hours; // hold hours worked
double payRate; // hold pay rate
double overTime; // hold overtime
double overTimeHours; // hold overtime hours
Scanner keyboard = new Scanner(System.in);
System.out.print("How many hours did you work this week? ");
hours = keyboard.nextDouble();
System.out.print("What is your pay rate? ");
payRate = keyboard.nextDouble();

if (hours > 40)
{
overTimeHours = (hours - 40);
overTime = overTimeHours * payRate * 1.5;
return (hours - overTimeHours) * payRate + overTime;
}
else
{
return (hours * payRate);
}
}

public static double HealthcareDeductions()
{
if (marriedHealthcare == true)
return 100;
if (singleHealthcare == true)
return 60;
return 0;

}



public static double getTaxablePay(double grossPay)
{
double taxPay;
int dependents;
String maritalStatus;
double Tax;
String healthcare;



Scanner keyboard = new Scanner(System.in);
System.out.print("What is you marital status?(married = M, single = S) ");
maritalStatus = keyboard.nextLine();
System.out.print("Do you have healthcare?(yes = Y, no = N) ");
healthcare = keyboard.nextLine();
System.out.print("How many dependents do you have? ");
dependents = keyboard.nextInt();


if (maritalStatus.equals("M"))
{
taxPay = grossPay - 150 - 70.0 * dependents;
System.out.println(healthcare);
if (healthcare.equals("Y"))
{
marriedHealthcare == true;
HealthcareDeductions();
taxPay = taxPay - 100;


}
System.out.println(taxPay);
if (taxPay > 800)
{
Tax = (taxPay - 800) * .35 + (800 - 500) * .25 + (500 - 200) * .15 +200 * .10;

return Tax;
}
else if (taxPay > 500)
{
Tax = (taxPay - 500) * .25 + (500 - 200) * .15 +200 * .10;
System.out.println(Tax);
return Tax;
}
else if (taxPay > 200)
{
Tax = (taxPay - 200) * .15 +200 * .10;
return Tax;
}
else
{
Tax = taxPay * .10;
return Tax;
}
}
else
{
taxPay = grossPay - 75 - 70.0 * dependents;

if (healthcare.equals("Y"))
{
taxPay = taxPay - 60;
singleHealthcareDeductions();
}
if (taxPay > 400)
{
Tax = (taxPay - 400) * .35 + (400 - 250) * .25 + (250 - 100) * .15 +100 * .10;

}
else if (taxPay > 250)
{
Tax = (taxPay - 250) * .25 + (250 - 100) * .15 +100 * .10;
}
else if (taxPay > 100)
{
Tax = (taxPay - 100) * .15 +100 * .10;
}
else
{
Tax = taxPay * .10;
}
}
return Tax;

}

public static double getFedTax(double grossPay, double taxablePay)
{
return (grossPay - taxablePay);
}

public static double getNetPay(double taxablePay, double federalTax)
{
return (federalTax - taxablePay); //I know this is wrong. I can't get healthcare costs to this point in the program for some reason.
} //I am so used to how easy C# is :(
public static void displayResults(double grossPay, double federalTax, double taxablePay, double net, String name)
{
System.out.println("Employee name: " + name);
System.out.println("Gross pay is " + grossPay);
System.out.println("Taxable pay is " + federalTax);
System.out.println("Tax is " + taxablePay);
System.out.println("Your net pay is " + net);
}
}


Your help is much appreciated 
Cheers Ty

Answers (4)