1. Member
Join Date
Oct 2013
Posts
1
Rep Power
0

## Wage Calculaor Total Pay is always 0. Help please?

Hello all, first post here. For my high school CS class we had to make a wage calculator using methods, but every time I run it, it returns the totalPay as 0.0. What's going wrong?
Java Code:
```import java.util.Scanner;
import java.lang.*;

public class Wage_Calculator {

private static int employeeID;
private static double hourlyWage;
private static double regularHours;
private static double overtimeHours;
private static double totalPay;
private static String name;

public static void main(String[] args) {

employeeName();
inputEmployeeID();
inputHourlyWage();
inputRegHours();
inputOverHours();
calcTotalPay();

}

public static void employeeName()    {
//Enter employee name
Scanner scan4 = new Scanner(System.in);
name = scan4.nextLine();
}
public static void inputEmployeeID() {
//Input Employee ID
Scanner scan = new Scanner(System.in);
int employeeID = scan.nextInt();
}

public static void inputHourlyWage() {
//Enter in the hourly wage
System.out.println("What is your hourly wage? ");
Scanner scan1 = new Scanner(System.in);
double hourlyWage = scan1.nextDouble();
}

public static void inputRegHours() {
//Enter how many regular hours were worked
System.out.println("Enter number of regular hours worked: ");
Scanner scan2 = new Scanner(System.in);
double regularHours = scan2.nextDouble();
}

public static void inputOverHours() {
//Enter how many overtime hours were worked
System.out.println("Enter number of overtime hours worked: ");
Scanner scan3 = new Scanner(System.in);
double overtimeHours = scan3.nextDouble();
}

public static void calcTotalPay() {
//The total pay comes out to:
totalPay = (regularHours * hourlyWage) + (overtimeHours * (hourlyWage * 1.5));
System.out.println(name + ", your total pay for this week is: \$" + totalPay);
}

}```

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,926
Rep Power
10

## Re: Wage Calculaor Total Pay is always 0. Help please?

You're hiding you class fields by redeclaring them in your methods. So don't redeclare them.

And on an unrelated note: Don't declare the fields static. And you only need one scanner instance.

Regards,
Jim

3. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Wage Calculaor Total Pay is always 0. Help please?

As per jim829's explanation:

Originally Posted by nathanskates
Java Code:
```public class Wage_Calculator {

private static double hourlyWage;   // you are not updating THIS hourlyWage variable...

public static void inputHourlyWage() {
//Enter in the hourly wage
System.out.println("What is your hourly wage? ");
Scanner scan1 = new Scanner(System.in);
double hourlyWage = scan1.nextDouble();  // ... but you are updating THIS hourlyWage variable
}

}```
Seems like a bit of copy/paste mistakery here ;)

4. Moderator
Join Date
Apr 2009
Posts
13,323
Rep Power
23

## Re: Wage Calculaor Total Pay is always 0. Help please?

Originally Posted by jim829
And on an unrelated note: Don't declare the fields static.
Since every method is static then the fields need to be.

5. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,926
Rep Power
10

## Re: Wage Calculaor Total Pay is always 0. Help please?

Yeah. I didn't notice that. @OP don't make you methods static either. :)

Regards,
Jim

6. Senior Member
Join Date
Jan 2011
Location
Posts
311
Rep Power
7

## Re: Wage Calculaor Total Pay is always 0. Help please?

@OP don't make you methods static either. :)

7. ## Re: Wage Calculaor Total Pay is always 0. Help please?

Originally Posted by jim829
don't make you methods static either.
Cue whine about getting "Cannot make a non-static reference from a static context" error. (or whatever the wording is)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•