xveilsidex
Utente Attivo
- Messaggi
- 230
- Reazioni
- 7
- Punteggio
- 38
Ciao a tutti qualcuno potrebbe darmi una mano per la creazione di questo metodo java ?
]HO PROVATO IN QUESTA MANIERA NON NON FUNZIONA
Codice:
L'inserimento di un elemento può essere impedito a causa dei seguenti casi:
1. L'identificatore è già presente nel contenitore;
2. La stringa è nulla;
3. Il contenitore è pieno;
4. L'identificatore non è un intero positivo
Anziché restituire un valore Boolean, il servizio restituirà una delle seguenti costanti intere,
definite nella classe StringPool e rese pubbliche:
SUCCESS se l'inserimento è avvenuto correttamente;
KO_DUPLICATE_FOUND se si è verificato il caso 1;
KO_NULL_STRING se si è verificato il caso 2;
KO_FULL_POOL se si è verificato il caso 3.
ID_NOT_VALID se si è verificato il caso 4.
Codice:
public int add(int id, String word){
int n = str.length;
int statment = 0;
for(int i = 0; i < n; i++){
if(str[i].getID() == id){
System.out.println("duplicate found");
return statment = KO_DUPLICATE_FOUND;
}
else if(word == ""){
System.out.println("null string");
return statment = KO_NULL_STRING;
}
else if(str[i] == null && i < n){
System.out.println("full pool");
return statment = KO_FULL_POOL;
}
else if(id < 0 ){
System.out.println("id non valido");
return statment = ID_NOT_VALID;
}
else{
str[i] = new StringUtils(id,word);
System.out.println("STRING_POOL_SUCCES Code Return : " + STRING_POOL_SUCCESS);
return statment = STRING_POOL_SUCCESS;}
}
return statment;
}