Note that there are some explanatory texts on larger screens.

plurals
  1. POI need help with a program ia m writing in JAVA ( nullpointer exception)
    text
    copied!<p>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.</p> <p>here is my code in Salesman class </p> <pre><code> 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&lt;=order.length;) { grossSales+=order[i++].getamount(); //get the value of the sales done System.out.println(grossSales); } if (grossSales&lt;10000 ){ baseSalary+=baseSalary*0.05; } else if((grossSales&gt;=10000)||(grossSales&lt;=20000)){ baseSalary+=baseSalary*0.07; } else baseSalary+=baseSalary*0.1; } </code></pre> <p>in main i have </p> <pre><code>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); </code></pre> <p>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 </p> <blockquote> <p>Exception in thread "main" java.lang.NullPointerException</p> </blockquote> <pre><code> at misthodosia.Salesman.setSallary(Salesman.java:36) at misthodosia.Salesman.&lt;init&gt;(Salesman.java:28) at misthodosia.Misthodosia.main(Misthodosia.java:30) </code></pre> <p>Java Result: 1</p> <p>heres the Orders class as well</p> <pre><code>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; } </code></pre> <p>}</p> <p>Can you help me ?? I know i am doing something wrong with the object array but i cant figure it out :S </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload