I am taking a programming class and set up code about computing a paycheck. Everything works fine except for line 11. I end up getting a stackoverflow error.
However when I remove this line of code
double weeksWages = pay(50, 10); // weeksWages is 550
The error goes away, but when running program, I end up with 10 instead of 550 that is intended. This is probably really simple to fix, but not sure. Thanks!
Here is the full code:
import java.util.Scanner;
import static java.lang.System.out;
public class ComputePayCheck {
static Scanner in = new Scanner(System.in);
public static double pay(int hours, double hourlyRate) {
int otHours = (hours > 40) ? hours - 40 : 0;
double weeksWages = pay(50, 10); // weeksWages is 550
return otHours;
}
public static void main(String[] args) {
out.print("Enter hours worked: ");
int hours = in.nextInt();
out.print("Enter hourly rate: ");
double hourlyRate = in.nextDouble();
out.print("Week's Salary is: " + pay(hours, hourlyRate));
}
}
double weeksWages = pay(50, 10); // weeksWages is 550has no effect, other than generating the stack overflow.