public void addAssegurança(Assegurança a) throws Exception { // Hi ha lloc? if (this.quantesAssegurances + 1 > this.maxAssegurances) throw new Exception( "La companyia no pot contractar més assegurançes (Max:" + this.maxAssegurances + ")"); // Està repetit? for (Assegurança item : this.assegurances) { if (item != null) { if (item.equals(a)) { throw new Exception("Ja existeix l'assegurança " + a.toString()); } ; } } // Agent contractat? boolean trobat = false; for (Agent item : this.agents) { if (item.equals(a.getCorredor())) { trobat = true; } } if (!trobat) { throw new Exception("Agent no està contractat " + a.toString()); } ; // Si la persona que fa la contractació no era client de la companyia també s’ha d’afegir al // corresponent magatzem de clients if (!this.existsClient(a.getClient())) { Node nouClient = new Node(a.getClient(), null); // Si no hi ha clients, afegir la referencia if (this.clients == null) this.clients = nouClient; else { // Afegir el node a l'ultim de la seqüencia enllaçada. this.getLastNode().setSeguent(nouClient); } } this.contadorPolisses++; a.setNumeroPolissa(this.contadorPolisses); this.assegurances[quantesAssegurances] = a; quantesAssegurances++; };