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

• 10-31-2013, 05:07 PM
nathanskates
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?
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         System.out.println("Please enter your full name: ");         Scanner scan4 = new Scanner(System.in);         name = scan4.nextLine(); } public static void inputEmployeeID() { //Input Employee ID         System.out.println("Please enter your 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);   } }```
• 10-31-2013, 05:13 PM
jim829
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
• 10-31-2013, 06:10 PM
gimbal2
Re: Wage Calculaor Total Pay is always 0. Help please?
As per jim829's explanation:

Quote:

Originally Posted by nathanskates
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 ;)
• 10-31-2013, 06:15 PM
Tolls
Re: Wage Calculaor Total Pay is always 0. Help please?
Quote:

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.
• 10-31-2013, 06:24 PM
jim829
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
• 10-31-2013, 10:35 PM
milovan
Re: Wage Calculaor Total Pay is always 0. Help please?
Quote:

@OP don't make you methods static either. :)
:)-:
• 11-01-2013, 05:55 AM
Junky
Re: Wage Calculaor Total Pay is always 0. Help please?
Quote:

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)