Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Greetings ,
i have the following code and i am trying to use a table-array to store my manager objects. But on the syntax level i cannot get this done. Can anybody take a look on my code and tell me what i am doing wrong ?


Java
public class Secretaire extends Employe{

    public int nbManager = 0;
    public Manager managers[];

    public Secretaire(int salaire, GregorianCalendar dateEmbauche, String leNom, String lePrenom, GregorianCalendar laDate, Adresse lAdresse) {
        super(salaire, dateEmbauche, leNom, lePrenom, laDate, lAdresse);
        managers = new Manager[5];
    }

  public void addManager(Manager m,int i){        //method addManager
    
      for(i = 0;this.managers.length < 5;i++)
         managers[i] = new m();                  //cannot find symbol m ?
     }  
     }
Posted

Please make it:

Java
public final Manager managers[];


...to make sure the constructor is forced to init the Array.

Would also be cool to use an ArrayList - if possible and yet known.
 
Share this answer
 
Comments
voronitski.net 19-Nov-14 4:40am    
Sorry my Professor want me use "Table Arrays"
Java
<pre lang="cs">public void addManager(Manager m){
  int i = 0;
       while (managers[i] != null)
           i++;
           managers[i] = m;
        if (i == 5)
            System.out.println("Erreur ,le secretaire est trop occupé (MAX5)");
   }



So what i have done is that:
1. first i deleted from method parameters the INT I value
public void addManager(Manager m) ,beacause i don t want it as a "giving value" but as a counter in the method.
2.I decided to use WHILE loop to base from that the array is empty from the beginning.
3.When is 5 throw message of array gap is max.
 
Share this answer
 
Comments
TorstenH. 19-Nov-14 8:40am    
ok, now I got it. well, a bit odd, but might work for the moment (and limited coding you are allowed).
voronitski.net 19-Nov-14 10:25am    
Yes i agree ,but it is first time i am using table arrays with objects
Don't you mean:
Java
managers[i] = new Manager();
 
Share this answer
 
if you need to add manager in to given index
C#
public void addManager(Manager m,int i){        
       if(this.managers.length>i){
           managers[i] = m;   
        }               
}  
 
Share this answer
 
Comments
voronitski.net 19-Nov-14 4:17am    
So if my table array will be equal the limit of 5 ,will it end to add the objects ,or it will continue to add them?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900