Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package park.grad;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.nio.Buffer;
- import java.util.ArrayList;
- import java.util.GregorianCalendar;
- import java.util.List;
- import park.Park;
- import park.SpravaZaZabavu;
- import park.TipSpraveZaZabavu;
- public class GradskiParkovi {
- private List<Park> parkovi = new ArrayList<>();
- public void unesi(Park park) {
- if(park == null || parkovi.contains(park))
- return;
- parkovi.add(park);
- }
- public void pretrazi(int uzrast) {
- try (PrintWriter in = new PrintWriter(
- new BufferedWriter(
- new FileWriter("parkovi.txt")))) {
- int brojac=0;
- for(int i=0;i<parkovi.size();i++) {
- if(parkovi.get(i).getSprave()==null) {
- in.close();
- return;
- }
- for(int j=0;j<parkovi.get(i).getSprave().length;j++) {
- if(parkovi.get(i).getSprave()[j].getUzrast()>=uzrast) {
- brojac++;
- }
- }
- if(brojac>0) {
- in.println(parkovi.get(i).getAdresa());
- }
- }
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void pronadjiPa(int uzrast) {
- try (PrintWriter in = new PrintWriter(
- new BufferedWriter(
- new FileWriter("rekoviranje.txt")))) {
- int brojac = 0;
- int n = 0;
- for(int i=0;i<parkovi.size();i++) {
- if(parkovi.get(i).getSprave()==null) {
- in.close();
- return;
- }
- n = parkovi.get(i).getSprave().length;
- int br2 = 0;
- String stariParkovi = "";
- String adreseStarihParkova = "";
- for(int j=0;j<parkovi.get(i).getSprave().length;j++) {
- GregorianCalendar datum = parkovi.get(i).getSprave()[j].getDatumPostavljanja();
- GregorianCalendar trenutni = new GregorianCalendar();
- int godina = datum.get(GregorianCalendar.YEAR);
- int trenutnaGodina = trenutni.get(GregorianCalendar.YEAR);
- if(godina + 3 <= trenutnaGodina) {
- stariParkovi=stariParkovi+parkovi.get(i).toString()+"\n";
- brojac++;
- }
- adreseStarihParkova=adreseStarihParkova + parkovi.get(i).getAdresa() + "\n";
- br2++;
- }
- if(brojac > n/2) {
- in.println(adreseStarihParkova);
- in.println(stariParkovi);
- }
- }
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static String unos() throws IOException {
- BufferedReader out = new BufferedReader(new InputStreamReader(System.in));
- String uneto = out.readLine();
- return uneto;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement