brandonscott
brandonscott

Reputation: 71

(double,int) cannot be applied to (double)

Been wracking my brain for hours trying to figure this out.

i have the main method which is:

public static void main(String [] args)
    {
        double payRate;
        double grossPay;
        double netPay;
        int hours;

        Scanner input = new Scanner(System.in);

        System.out.println("Welcome to the Pay Roll Program");

        printDescription(); 

        System.out.print("Please input the pay per hour: ");
        payRate = input.nextDouble();

        System.out.println("\nPlease input the pay per hour: ");
        hours = input.nextInt();
        System.out.println("\n");


        netPay = computePaycheck(netPay);

        System.out.println("The net pay is $" + (netPay));
        System.out.println("We hope you enjoyed this program");

        System.exit(0);

and the method that calculated the netPay

public static double computePaycheck(double payRate, int hours)
{


    double grossPay = computePaycheck(payRate*hours);

    double netPay = (grossPay - (grossPay *.15));

    return netPay;

}

But I'm getting the error "computePaycheck(double,int) in PayCheck cannot be applied to (double)"

I sort of understand this, but I can't for the life of me figure out a remedy.

Upvotes: 0

Views: 2507

Answers (6)

Stephen Olujare
Stephen Olujare

Reputation: 11

It's clear that you set 2 parameters but from the main class you are only calling just one parameter. You should find a way to call the 2 parameters at the same time.

Upvotes: 0

bernie
bernie

Reputation: 10390

The first statement of your computePaycheck method calls computePaycheck with a single parameter (a double) whereas the computePaycheck takes 2 parameters (a double and an int). That is why your code fails to compile.

If you "fix" this by using double grossPay = computePaycheck(payRate, hours); instead, this will compile BUT you will get infinite recursion! Don't you simply want to do double grossPay = payRate*hours; ?

Upvotes: 0

Matt
Matt

Reputation: 1242

1) You are calling a function with 2 parameters while only passing 1. That will cause a compilation error.

2) When you call computePaycheck from within itself that will loop and cause a stack overflow.

Upvotes: 2

Deltik
Deltik

Reputation: 1137

Your method takes two parameters -- double payRate and int hours, but you are only specifying a double when you call computePaycheck in your main method.

It's not clear what you intend to happen, but the mismatched parameters should let you know what is wrong with your program.

Upvotes: 0

Jon Newmuis
Jon Newmuis

Reputation: 26502

In your computePaycheck method, you have the following line:

double grossPay = computePaycheck(payRate*hours);

This is passing one parameter (the product of payRate and hours) to the computePaycheck function, which requires two parameters. It looks like you meant to say:

double grossPay = computePaycheck(payRate, hours);

But you will need to be careful! This will cause your program to recur infinitely! You will need to determine how to calculate the gross pay without calling this function, since if you do call it recursively within itself, there is no condition from which it will return.

Upvotes: 0

Thilo
Thilo

Reputation: 262534

netPay = computePaycheck(netPay);

public static double computePaycheck(double payRate, int hours)

"computePaycheck(double,int) in PayCheck cannot be applied to (double)"

Your method takes two parameters, a double and an int.

You can only call it with those two (you are missing the number of hours in the call).

netPay = computePaycheck(payRate, hours);

double grossPay = payRate*hours;

Upvotes: 0

Related Questions