Advertisement
Guest User

Zboruri

a guest
Jun 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1. package subiectstrategy;
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. class Zbor {
  6.     int ora_plecare;
  7.     int ora_sosire;
  8.     String ruta;
  9.    
  10.     public void setOraPlecare(int ora){
  11.         ora_plecare = ora;
  12.     }
  13.    
  14.     public void setOraSosire(int ora){
  15.         ora_sosire = ora;
  16.     }
  17.    
  18.     public void setRuta(String r){
  19.         ruta = r;
  20.     }
  21.    
  22.     public String toString(){
  23.         return "Zbor de la " + ora_plecare + " la " + ora_sosire + " pe ruta " + ruta;
  24.     }
  25. }
  26.  
  27. class Avion {
  28.     List<Zbor> zboruri = new ArrayList();
  29.    
  30.     public void colecteazaZboruri() throws FileNotFoundException, IOException {
  31.         String filename = "./src/subiectstrategy/lzboruri";
  32.         BufferedReader in = new BufferedReader(new FileReader(filename));
  33.        
  34.         String s;
  35.         while((s=in.readLine())!=null){
  36.             String info[] = new String[3];
  37.             info = s.split(" ");
  38.            
  39.             Zbor z = new Zbor();
  40.             z.setOraPlecare(Integer.parseInt(info[0]));
  41.             z.setOraSosire(Integer.parseInt(info[1]));
  42.             z.setRuta(info[2]);
  43.            
  44.             zboruri.add(z);
  45.         }
  46.        
  47.         in.close();
  48.     }
  49.    
  50.     public void afisareZboruri(){
  51.         for(Zbor z: zboruri){
  52.             System.out.println(z);
  53.         }
  54.     }
  55. }
  56.  
  57. class Pasager {
  58.     String nume;
  59.     String prenume;
  60.     String zona;
  61.    
  62.     Pasager(String n, String pn, String z){
  63.         nume = n;
  64.         prenume = pn;
  65.         zona = z;
  66.     }
  67. }
  68.  
  69. class Aeroport {
  70.     List<Pasager> pasageri = new ArrayList();
  71.     String nume_oras;
  72.    
  73.     public void pasager_nou(Pasager p){
  74.         pasageri.add(p);
  75.     }
  76.    
  77. }
  78.  
  79. interface Deplasare{
  80.     public void condu(Pasager p);
  81. }
  82.  
  83. class Taxi implements Deplasare{
  84.     public void condu(Pasager p){
  85.         System.out.println("Pasagerul " + p.nume + " " + p.prenume + " a hotarat sa ia taxi-ul");
  86.     }
  87. }
  88.  
  89. class MasinaInchiriata implements Deplasare{
  90.     public void condu(Pasager p){
  91.         System.out.println("Pasagerul " + p.nume + " " + p.prenume + " a hotarat sa inchirieze o masina");
  92.     }
  93. }
  94.  
  95. class Autobus implements Deplasare{
  96.     public void condu(Pasager p){
  97.         System.out.println("Pasagerul " + p.nume + " " + p.prenume + " a hotarat sa ia un autobuz");
  98.     }
  99. }
  100.  
  101. public class Subiectstrategy {
  102.     public static void proceseaza(Deplasare d, Pasager p){
  103.         d.condu(p);
  104.     }
  105.    
  106.     public static void main(String[] args) {
  107.         Aeroport a = new Aeroport();
  108.         Pasager p = new Pasager("Victor", "Razvan", "Sosiri");
  109.         a.pasager_nou(p);
  110.        
  111.         proceseaza(new Taxi(), p);
  112.        
  113.         Avion av = new Avion();
  114.        
  115.         try{
  116.             av.colecteazaZboruri();
  117.             av.afisareZboruri();
  118.         } catch (IOException excep) {
  119.             System.out.println("sry");
  120.         }
  121.     }
  122.    
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement