Advertisement
spiny94

Untitled

Sep 2nd, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.Map;
  5. import java.util.TreeMap;
  6. public class Sanita {
  7.  
  8.     private Map<String,Persona> persone = new TreeMap<String,Persona>();
  9.     private Map<String,Medico> medici = new TreeMap<String,Medico>();
  10.     public void aggiungiPersona(String nome, String cognome, String cf){
  11.         Persona p = new Paziente(nome,cognome,cf);
  12.         persone.put(cf, p);
  13.        
  14.     }
  15.     public Persona getPersona(String cf) throws ErrPersonaInesistente{
  16.         if(! persone.containsKey(cf))
  17.         {throw new ErrPersonaInesistente();}
  18.         return persone.get(cf);}
  19.    
  20.     public void aggiungiMedico(String matricola, String nome, String cognome, String cf){
  21.        
  22.         Medico m = new Dottore(matricola,nome,cognome,cf);
  23.         medici.put(matricola, m);
  24.         persone.put(cf, m);
  25.     }
  26.     public Medico getMedico(String matricola) throws ErrMedicoInesistente
  27.     {           if(! medici.containsKey(matricola)){
  28.         throw new ErrMedicoInesistente();
  29.     }
  30.         return medici.get(matricola);
  31.     }
  32.     public void assegnaMedico(String matricola,String cf)
  33.     throws ErrPersonaInesistente, ErrMedicoInesistente {
  34.        
  35.         // devo recuperare paziente, medico e fare in modo
  36.         //che i due si incrocino
  37.        
  38.     Persona p = getPersona(cf);
  39.         Medico m = getMedico(matricola);
  40.         // così non serve usare le eccezioni
  41.         ((Paziente)p).setMedico(m);
  42.         ((Dottore)m).addPaziente(p);
  43.     }
  44.     public int caricaDati(String nomeFile) throws IOException{
  45.         BufferedReader r= new BufferedReader(new FileReader(nomeFile));
  46.         String line;
  47.         while ((line = r.readLine())!= null){
  48.             String[] elementi = line.split(";");
  49.             if (elementi.length>=0)
  50.            
  51.             if (elementi[0].trim().equals("P")){
  52.                
  53.                 aggiungiPersona(elementi[1], elementi[2], elementi[3]);
  54.                 // pazienti
  55.             }
  56.             else
  57.             if (elementi[0].trim().equals("M")){
  58.                 //medici
  59.                 aggiungiMedico(elementi[1], elementi[2], elementi[3], elementi[4]);
  60.             }
  61.            
  62.         }
  63.         return 0;
  64.     }  
  65. }
  66. public interface Persona extends Comparable<Persona> {
  67.     public abstract String getNome();
  68.     public abstract String getCognome();
  69.     public abstract Medico getMedico();
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement