public class GestionProtocole { private BanqueSimple bs; public GestionProtocole() { bs = new BanqueSimple(); } public String traite(String requete){ if(requete != null){ String [] tab = requete.split(" "); switch(tab[0]){ case "CREATION": if(tab.length == 3){ if(bs.compteExiste(tab[1])) { return "ERREUR Compte déjà existant"; } try { double somme = Double.parseDouble(tab[2]); bs.creerCompte(tab[1], somme); return "OK CREATION"; } catch (Exception e){ e.printStackTrace(); } } break; case "POSITION": if(tab.length == 2){ if(bs.compteExiste(tab[1])) { return "POS " + bs.getSolde(tab[1]) + " " + bs.getDerniereOperation(tab[1]); } else { return "ERREUR compte inexistant"; } } break; case "AJOUT": if (tab.length == 3) { if (bs.compteExiste(tab[1])) { try { double somme = Double.parseDouble(tab[2]); bs.ajouter(tab[1], somme); return "OK AJOUT"; } catch (Exception e) { e.printStackTrace(); } } } break; case "RETRAIT": if (tab.length == 3) { if (bs.compteExiste(tab[1])) { try { double somme = Double.parseDouble(tab[2]); if (bs.getSolde(tab[1]) >= somme) { bs.retirer(tab[1], somme); return "OK RETRAIT"; } else { return "KO RETRAIT: pas assez d'argent sur le compte"; } } catch (Exception e) { e.printStackTrace(); } } } break; } } return "ERREUR Requête mal formée"; } }