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 3402166
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:06:17+00:00 2026-05-18T05:06:17+00:00

i ma trying to write a program where about the payments of employees and

  • 0

i ma trying to write a program where about the payments of employees and other staaff, I have an abstract superclass called Employee, and then the following FullTimeEmployee,PartTimeEmployee ,Orders and Salesman , are sub classes of Employee.
I have only one problem with null pointers in Salesman, where i try to calculate the bonus they will get for each sale.

here is my code in Salesman class

    public Salesman(String firstname, String lastname,int code, String address, String city,int tk,int phone,String email,int deptcode,int card,double hours,String cat,int orderno,double salary,Orders[] ord/*,double sales*/){
 super(  firstname, lastname, code,  address, city, tk, phone, email, deptcode, card, hours, cat );
 this.orderno=orderno;
 setBaseSalary( salary );

 //setGrossSales( sales );
 Orders[] order= ord.clone();//new Orders[orderno];//create the array for the orders made by this salesman
 //order=ord;
 setSallary(order );
 }



public void setSallary( Orders[] order ){
    //double sum=0;
    for(int i=0;i<=order.length;) {
       grossSales+=order[i++].getamount(); //get the value of the sales done
       System.out.println(grossSales);
    }
    if (grossSales<10000 ){

        baseSalary+=baseSalary*0.05;
    }
    else if((grossSales>=10000)||(grossSales<=20000)){
        baseSalary+=baseSalary*0.07;
    }
    else
        baseSalary+=baseSalary*0.1;


}

in main i have

Orders[] array=new Orders[20];
   array[0]=new Orders(1,"14/5/2010","agora aftolinitwn",2000.0);
   array[1]=new Orders(2,"14/5/2010","agora aftolinitwn",20000.0);

   Salesman sales1 =new Salesman("giannis", "antoniou",35, "vavilonos 7", "leffkosia",11475,69486931,"gäntoniou@hotmail.com",100,40,160.0,"salesman",2,1300.0,array);
   Salesman sales2 =new Salesman("andreas", "antoniou",35, "vavilonos 7", "lefkosia",11475,69486931,"äntonioua@hotmail.com",100,41,160.0,"salesman",1,1200.0,array);

basically what i do is creating an array with the salsmans info( amount earned from sale etc) and then sending it in to Saleman Constructor. i then copy the conents of tha array to another array an try to calulate the bonus. but i get

Exception in thread “main” java.lang.NullPointerException

    at misthodosia.Salesman.setSallary(Salesman.java:36)
    at misthodosia.Salesman.<init>(Salesman.java:28)
    at misthodosia.Misthodosia.main(Misthodosia.java:30)

Java Result: 1

heres the Orders class as well

public class Orders {
private int orderNo;
private String orderDate;
private String description;
private double orderAmount;
private Salesman man;


public Orders(int no,String date,String descrip,double amount/*,Salesman man*/){
    orderNo=no;
    orderDate=date;
    description=descrip;
    orderAmount=amount;
    //this.man=man;

    //Orders[] orders=new Orders[orderNo];//create the array for the orders made by this salesman



}


public double getamount(){
    return orderAmount;
}

}

Can you help me ?? I know i am doing something wrong with the object array but i cant figure it out :S

  • 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-18T05:06:17+00:00Added an answer on May 18, 2026 at 5:06 am

    It is on this line:

    grossSales+=order[i++].getamount();

    The order array is allocated to a size of 20, but only the first 2 are initialized, therefore when it accesses order[2].getamount() that value is null, hence the null pointer.

    I strongly recommend using an ArrayList for the list of orders, you don’t have to preallocate a number of orders.

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

Sidebar

Related Questions

i am trying to write a program that close explorer then runs another program.
Hii , I have been trying to write a program... We have a structure
Im making a program about the game Go and im trying to write some
I am trying to write a program to collect security information about a file
I'm trying to write a prolog program that behaves in the following fashion: it
I am trying to write a program that does the following: Takes values of
I have been trying to write a program to convert my father's old PTS.
I am trying to write a simple program about UDP Connections to learn about
I have a few basic questions about sockets programming. I am trying to write
I am trying to re-write a program in C to java. I have no

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.