How to use an attribute of an object to increment a counter?

2

I have the exercise practically solved, only one "counter" is missing.

"In order to determine the monthly amount to be received by each employee, the customers they collect should be counted. Each client must have an attribute with the identification of the employee who collected it." >

One of the attributes of each Client is the name of the employee who "got it". How can I make an increase in the number of clients of the Employee by increasing the number of clients that I have raised? By browsing an array with Clients, Employees and even some other types of objects (all of the same super class)

I hope you can see the doubt, I'm having a hard time explaining what I want.

    
asked by anonymous 05.04.2014 / 18:46

1 answer

2

In the class of the official you can have a list of clients (0 for N) In the client class have a reference from 0 to 1 with the official who has agariou In the agarar method (in the employee class) it receives the client class as a reference and adds it in the official's employee list and arrows the reference of the official who has agariou.

In other words, in C # it would look like this, (in Java it should look good):

private abstract class Pessoa {
    private string nome_;
}

private class Funcionario : Pessoa {
    private List<Cliente> clientesAgariados_ = new List<Cliente>();

    private void Agariar(Cliente cliente) { 
        cliente.setAgariador(this);
        clientesAgariados.add(cliente);
    }

    public int ClientesAgariados()
    {
        return clientesAgariados.count;
    }
}

private class Cliente : Pessoa {
    private Funcionario agariador_;

    public void setAgariador(Functionario funcionario)
    {
        agariador_ = funcionario;
    }
}

In the main method you do what you need and check the number of clients gathered by the ClientAccessed function:

public static Main() {
     Funcionario funcionario = new Funcionario;
     Cliente cliente1 = new Cliente;
     Cliente cliente2 = new Cliente;

     funcionario.Agariar(cliente1);
     funcionario.Agariar(cliente2);

     Console.WriteLine(funcionario.ClientesAgariados().toString());
}
    
05.04.2014 / 18:57