Advertisement
pseudocreator

OOP1, k2, z1, DomZdravlja

Nov 5th, 2015
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.94 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3.  
  4. public class DomZdravlja {
  5.  
  6.   public static final String FILE_IN = "lekari.txt";
  7.    
  8.   public static void main(String[] args){
  9.  
  10.     Lekar[] domZdravlja = ucitajLekare();
  11.     stampajLekare(domZdravlja);
  12.    
  13.     //String imeLekara = "Pera";
  14.     //stampajKolegeIzSmene(imeLekara);
  15.     //stampajNajtrazenijegLekara();
  16.   }
  17.  
  18.   //ToDo: izSmene, najtrazenijeg
  19.  
  20.   //private static void stampajKolegeIzSmene(String ime){}
  21.  
  22.   //private static void stampajNajtrazenijegLekara(){}
  23.  
  24.   private static Lekar[] ucitajLekare(){
  25.     Lekar[] res = null;
  26.     try{
  27.     BufferedReader reader = new BufferedReader(new FileReader(FILE_IN));
  28.    
  29.     int num = Integer.parseInt(reader.readLine());
  30.     res = new Lekar[num];
  31.    
  32.     for(int i = 0; i < num; i++){
  33.      
  34.       String line = reader.readLine();
  35.      
  36.       String[] lines = line.split(",");
  37.      
  38.       String ime = lines[0].trim();
  39.       int brojRecepata = Integer.parseInt(lines[1].trim());
  40.       int smena = Integer.parseInt(lines[2].trim());
  41.      
  42.       if(lines.length <= 3){
  43.         res[i] = new Lekar(ime, brojRecepata, smena); //kreiranje lekara
  44.       } else {  
  45.         //prebroj
  46.         int preostalih = lines.length - 3;
  47.         Lekar[] uputi = new Lekar[preostalih];
  48.         for(int p = 0; p < preostalih; p++){ //p = 3; p < lines.length
  49.          
  50.           for(int z = 0; z < i; z++){
  51.             if(res[z].getIme().equals(lines[p+3].toString().trim())){
  52.               uputi[p] = res[z];
  53.             }
  54.           }          
  55.         }
  56.         res[i] = new Specijalista(ime, brojRecepata, smena, uputi);
  57.       }  
  58.     }
  59.    
  60.     reader.close();
  61.  
  62.     }catch(Exception e){
  63.       e.printStackTrace();
  64.     }
  65.     return res;
  66.   }
  67.  
  68.  
  69.   private static void stampajLekare(Lekar[] domZdravlja){
  70.     for(Lekar l: domZdravlja){
  71.       System.out.println(l.toString());
  72.     }
  73.   }
  74.  
  75. }
  76.  
  77. class Lekar {
  78.  
  79.   private String ime;
  80.   private int brojRecepata;
  81.   private int smena; //1, 2, 3
  82.  
  83.   public Lekar(String ime, int brojRecepata, int smena){
  84.    
  85.     this.ime = ime;
  86.     this.brojRecepata = brojRecepata;
  87.     this.smena = smena;
  88.   }
  89.  
  90.   public String getIme(){
  91.     return ime;
  92.   }
  93.  
  94.   public int getBrojRecepata(){
  95.     return brojRecepata;
  96.   }
  97.  
  98.   public int getSmena(){
  99.     return smena;
  100.   }
  101.  
  102.   @Override
  103.   public String toString(){
  104.     return "ime: " + ime + " ,broj recepata: " + brojRecepata + " ,smena: " + smena;
  105.   }
  106.  
  107. }
  108.  
  109. final class Specijalista extends Lekar {
  110.  
  111.   private Lekar[] uputi;
  112.  
  113.   public Specijalista(String ime, int brojRecepata, int smena, Lekar[] uputi){
  114.     super(ime, brojRecepata, smena);
  115.     this.uputi = uputi;
  116.   }
  117.  
  118.   @Override
  119.   public String toString(){
  120.     StringBuilder sb = new StringBuilder(super.toString() + " uputi: ");
  121.     for(Lekar l: uputi){
  122.       sb.append(l.getIme() + ", ");
  123.     }
  124.     return sb.toString();
  125.   }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement