Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- public class DomZdravlja {
- public static final String FILE_IN = "lekari.txt";
- public static void main(String[] args){
- Lekar[] domZdravlja = ucitajLekare();
- stampajLekare(domZdravlja);
- //String imeLekara = "Pera";
- //stampajKolegeIzSmene(imeLekara);
- //stampajNajtrazenijegLekara();
- }
- //ToDo: izSmene, najtrazenijeg
- //private static void stampajKolegeIzSmene(String ime){}
- //private static void stampajNajtrazenijegLekara(){}
- private static Lekar[] ucitajLekare(){
- Lekar[] res = null;
- try{
- BufferedReader reader = new BufferedReader(new FileReader(FILE_IN));
- int num = Integer.parseInt(reader.readLine());
- res = new Lekar[num];
- for(int i = 0; i < num; i++){
- String line = reader.readLine();
- String[] lines = line.split(",");
- String ime = lines[0].trim();
- int brojRecepata = Integer.parseInt(lines[1].trim());
- int smena = Integer.parseInt(lines[2].trim());
- if(lines.length <= 3){
- res[i] = new Lekar(ime, brojRecepata, smena); //kreiranje lekara
- } else {
- //prebroj
- int preostalih = lines.length - 3;
- Lekar[] uputi = new Lekar[preostalih];
- for(int p = 0; p < preostalih; p++){ //p = 3; p < lines.length
- for(int z = 0; z < i; z++){
- if(res[z].getIme().equals(lines[p+3].toString().trim())){
- uputi[p] = res[z];
- }
- }
- }
- res[i] = new Specijalista(ime, brojRecepata, smena, uputi);
- }
- }
- reader.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- return res;
- }
- private static void stampajLekare(Lekar[] domZdravlja){
- for(Lekar l: domZdravlja){
- System.out.println(l.toString());
- }
- }
- }
- class Lekar {
- private String ime;
- private int brojRecepata;
- private int smena; //1, 2, 3
- public Lekar(String ime, int brojRecepata, int smena){
- this.ime = ime;
- this.brojRecepata = brojRecepata;
- this.smena = smena;
- }
- public String getIme(){
- return ime;
- }
- public int getBrojRecepata(){
- return brojRecepata;
- }
- public int getSmena(){
- return smena;
- }
- @Override
- public String toString(){
- return "ime: " + ime + " ,broj recepata: " + brojRecepata + " ,smena: " + smena;
- }
- }
- final class Specijalista extends Lekar {
- private Lekar[] uputi;
- public Specijalista(String ime, int brojRecepata, int smena, Lekar[] uputi){
- super(ime, brojRecepata, smena);
- this.uputi = uputi;
- }
- @Override
- public String toString(){
- StringBuilder sb = new StringBuilder(super.toString() + " uputi: ");
- for(Lekar l: uputi){
- sb.append(l.getIme() + ", ");
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement