The methods grossPay()
and fedTax()
are not being computed for some reason.
- How do I return the
grossPay()
result,grosspay
? - How do I return the
fedTax()
result,taxtotal
? - Where would I compute
totalpay = grosspay - taxtotal
? - Since I cannot return
taxtotal
I can't tell if it is working, but did I correctly callgrosspay
anddependents
to compute thetaxtotal
?
Thank you!
import java.util.Scanner;
public class WorkPay {
public static void main(String args[]) {
WorkPay wagecalc = new WorkPay(); // 1. Instantiate the object WorkPay
WorkPay input = new WorkPay(); // 2. Reference the method to prompt for inputs
input.prompt4data();
input.display(); // 3. Reference the method to display the results
}
public void prompt4data() {
Scanner console = new Scanner(System.in);
System.out.println("How many hours have you worked?");
hours = console.nextDouble();
System.out.println("What is your wage rate?");
wage_rate = console.nextDouble();
System.out.println("How many dependents do you have?");
dependents = console.nextInt();
}
// private instance variables
private double hours;
private double wage_rate;
private int dependents;
private double grosspay;
private double totalpay;
private double tax;
private double dependenttax;
private double taxtotal;
public double grossPay() {
double total1 = 0;
double total2 = 0;
double total3 = 0;
if (hours <= 40) {
total1 = wage_rate * hours;
grosspay = total1;
}
else if (hours > 40 && hours <= 60) {
total2 = total1 + (wage_rate * 1.5) * (hours - 40);
grosspay = total2;
}
else {
total3 = total2 + (wage_rate * 2) * (hours - 60);
grosspay = total3;
}
return grosspay;
}
public void fedTax() {
tax = (0.10 * grosspay);
dependenttax = (25 * dependents);
taxtotal = tax + dependenttax;
if (tax < 0)
System.out.println("Taxt withheld can't be less than 0.");
}
public void display() {
System.out.println("The hours worked is: " + hours);
System.out.println("The hoursly rate is: " + wage_rate);
System.out.println("The number of dependents is: " + dependents);
System.out.println("The gross income is: " + grosspay);
System.out.println("The federal tax withheld is: " + taxtotal);
System.out.println("The take home pay is: " + totalpay);
}
}