DamSi

Untitled

May 27th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. package dopolnitelni_casovi.linkedlists;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7. import java.util.Collections;
  8. import java.util.List;
  9.  
  10. /**
  11.  * ----------------------------
  12.  * Project: APS
  13.  * Package: dopolnitelni_casovi.linkedlists
  14.  * Created on: 27.5.2016, 23:41
  15.  * IDE: IntelliJ IDEA
  16.  * ----------------------------
  17.  * Author: Damjan Miloshevski
  18.  * Web: http://damjanmiloshevski.mk/
  19.  * Phone: +389 (0)78 566 409
  20.  * Skype: damjan.milosevski
  21.  * LinkedIn: https://mk.linkedin.com/in/damjanmiloshevski
  22.  * GitHub: https://github.com/damsii
  23.  * Bitbucket: https://bitbucket.org/dam_si
  24.  */
  25. public class SLLKompanija {
  26.     public static void main(String[] args) throws IOException {
  27.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  28.         List<Vraboten> kompanija = new ArrayList<>();
  29.         try {
  30.             int N = Integer.parseInt(in.readLine());
  31.             for (int i = 0; i < N; i++) {
  32.                 int id = Integer.parseInt(in.readLine());
  33.                 int plata = Integer.parseInt(in.readLine());
  34.                 kompanija.add(new Vraboten(id, plata));
  35.             }
  36.             int plata = Integer.parseInt(in.readLine());
  37.             List<Vraboten> novi = removeLowerThan(kompanija, plata);
  38.             Collections.sort(novi, Collections.reverseOrder());
  39.             if (novi.isEmpty()) {
  40.                 System.out.println("nema");
  41.             } else {
  42.                 for (Vraboten v : novi) {
  43.                     System.out.println(v.toString());
  44.                 }
  45.             }
  46.  
  47.         } catch (NumberFormatException e) {
  48.             System.err.println("Pogresen vlez!");
  49.         }
  50.     }
  51.  
  52.     static List<Vraboten> removeLowerThan(List<Vraboten> employees, int amount) {
  53.         List<Vraboten> company = new ArrayList<>();
  54.         for (Vraboten vraboten : employees) {
  55.             if (vraboten.getPlata() >= amount) {
  56.                 company.add(vraboten);
  57.             }
  58.         }
  59.         return company;
  60.     }
  61. }
  62.  
  63. class Vraboten implements Comparable<Vraboten> {
  64.     private int ID;
  65.     private int plata;
  66.  
  67.     public Vraboten(int ID, int plata) {
  68.         this.ID = ID;
  69.         this.plata = plata;
  70.     }
  71.  
  72.     public int getID() {
  73.         return ID;
  74.     }
  75.  
  76.     public int getPlata() {
  77.         return plata;
  78.     }
  79.  
  80.     @Override
  81.     public String toString() {
  82.         return String.format("%d %d", ID, plata);
  83.     }
  84.  
  85.     @Override
  86.     public int compareTo(Vraboten o) {
  87.         return Integer.compare(ID, o.ID);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment