Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6876593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:29:49+00:00 2026-05-27T04:29:49+00:00

I am working on a program for class due today at midnight and I

  • 0

I am working on a program for class due today at midnight and I just can’t figure why it’s giving me this Null Point Exception error. I would really appreciate if you guys can look at my code and help me out.

The goal of the project is as follows..

  • Program Statement: Write a Payroll class that uses the following arrays as fields:

    • employeeId – an array of 7 integers to hold employee id numbers. The array field should be initialized with the following numbers:
      1. 5658845
      2. 4520125
      3. 7895122
      4. 8777541
      5. 8451277
      6. 1302850
      7. 7580489
    • hours – An array of seven integers to hold the number of hours worked by each employee
    • payRate – An array of seven doubles to hold each employee’s hourly rate.
    • wages – An array of seven doubles to hold each employee’s gross wages.

    The class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose ID number is stored in Element 0 of the employeeId array. That same employees pay rate should be stored in Element 0 of the payRate array. In addition to the appropriate accessor and mutator methods, the class should have a method that accepts an employee’s id number as an argument and returns the gross pay for that employee. Demonstrate the class in a complete program that displays each employee number and asks the user to enter the employee’s hours and pay rate. It should then display each employee’s id number and gross wages.

    • Input Validation : Do not accept negative values for numbers and numbers less than 6.00 for pay rate.

int[] employeeId;
int[] hours;
double[] payRate;
double[] wages;

Scanner kboard = new Scanner(System.in);

public ParrishPayroll(int[] ids){

    employeeId = new int[ids.length];
    // Copy the values in ids
    for (int index = 0; index < ids.length; index++)
        employeeId[index] = ids[index];

    System.out.println("Employee ID's");
    System.out.println(Arrays.toString(employeeId));

    System.out.println("Please enter the id number you would like to edit.");
        int input = kboard.nextInt();

        if(input == 5658845){
            int index = 0;
            setHours(index);
            }
        else if(input == 4520125){
            int index = 1;
            setHours(index);
            }
        else if(input == 7895122){
            int index = 2;
            setHours(index);
            }
        else if(input == 8777541){
            int index = 3;
            setHours(index);
            }
        else if(input == 8451277){
            int index = 4;
            setHours(index);
            }
        else if(input == 1302850){
            int index = 5;
            setHours(index);
            }
        else if(input == 7580489){
            int index = 6;
            setHours(index);
            }
        else {
            System.out.println("Invalid ID number!");

            }
}//end startSequence

public void setHours(int i){

    System.out.println("How many hours were worked?");
    hours[i] = kboard.nextInt();    
        if(hours[i] < 0){
            System.out.println("Please input a positive number.");
            kboard.nextInt(hours[i]);
            setPayRate(i);
        }
        else
            setPayRate(i);

}

public void setPayRate(int index){

    int input = index;

    System.out.println("What is the employee's pay rate?");
    payRate[input] = kboard.nextDouble();
        if(payRate[input] < 0){
            System.out.println("Please input a positive number.");
            payRate[input] = kboard.nextDouble();
            calcWages(input);
        }
        else if(payRate[index] < 6.00){
            System.out.println("Wages must be higher than $6.00.");
            payRate[input] = kboard.nextDouble();
            calcWages(input);
        }
}

public void calcWages(int index){

    int input = index;

    wages[input] = hours[input] * payRate[input];

}


public void getGross(int i){

    int input = i;

    if(input == 5658845){
        System.out.print("Employee number: " + input + " wages: " + wages[0]);
        }
    else if(input == 4520125){
        System.out.print("Employee number: " + input + " wages: " + wages[1]);
        }
    else if(input == 7895122){
        System.out.print("Employee number: " + input + " wages: " + wages[2]);
        }
    else if(input == 8777541){
        System.out.print("Employee number: " + input + " wages: " + wages[3]);
        }
    else if(input == 8451277){
        System.out.print("Employee number: " + input + " wages: " + wages[4]);
        }
    else if(input == 1302850){
        System.out.print("Employee number: " + input + " wages: " + wages[5]);
        }
    else if(input == 7580489){
        System.out.print("Employee number: " + input + " wages: " + wages[6]);
        }
    else {
        System.out.println("Invalid ID number!");
        getGross(input);
        }


   }


public static void main(String[] args){

    int[] idlist = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489};

    ParrishPayroll user1 = new ParrishPayroll(idlist);

    Scanner kboard = new Scanner(System.in);
    System.out.println("What employee would you like to see the gross wages for?");
    int i = kboard.nextInt();
    user1.getGross(i);    

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:29:49+00:00Added an answer on May 27, 2026 at 4:29 am

    It looks like you are not initializing the hours, payRate or wages variables, which means they are all null. When you call, say, hours[i] = kboard.nextInt() it will throw a NullPointerException because you can’t set the i th element of null.

    Make sure you have a line like hours = new int[whatever] before you try to use the hours variable (same for the other two). You’ve got it right for employeeId, so follow that pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help making this program for class. We are working with g++
I'm working on a program for class that takes in a number from 0
I'm working on a program for my C++ programming class, using wxWidgets. I'm having
how can i make java program working with multiple languages (frensh, english , arabic
I'm working on a program for class that reads data from a file, the
I'm working on a program for class that involves solving the Chinese Postman problem
Please have a glance at this program: class CopyCon { public: char *name; CopyCon()
I'm a beginner in C# and I'm working on this program consisting of 4
I'm working on a simple lex program for class, and in it I'm creating
I'm trying to make a working program from this example: http://msdn.microsoft.com/en-us/library/ms741870.aspx . I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.