DamSi

Untitled

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