Advertisement
DamSi

Untitled

May 29th, 2016
127
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.  * E-mail: d.miloshevski@gmail.com; contact@damjanmiloshevski.mk
  19.  * Skype: damjan.milosevski
  20.  * LinkedIn: https://mk.linkedin.com/in/damjanmiloshevski
  21.  * GitHub: https://github.com/damsii
  22.  * Bitbucket: https://bitbucket.org/dam_si
  23.  */
  24. public class SLLKompanija {
  25.     public static void main(String[] args) throws IOException {
  26.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  27.         List<Vraboten> kompanija = new ArrayList<>();
  28.         try {
  29.             int N = Integer.parseInt(in.readLine());
  30.             for (int i = 0; i < N; i++) {
  31.                 int id = Integer.parseInt(in.readLine());
  32.                 int plata = Integer.parseInt(in.readLine());
  33.                 kompanija.add(new Vraboten(id, plata));
  34.             }
  35.             int plata = Integer.parseInt(in.readLine());
  36.             List<Vraboten> novi = removeLowerThan(kompanija, plata);
  37.             Collections.sort(novi, Collections.reverseOrder());
  38.             if (novi.isEmpty()) {
  39.                 System.out.println("nema");
  40.             } else {
  41.                 for (Vraboten v : novi) {
  42.                     System.out.println(v.toString());
  43.                 }
  44.             }
  45.  
  46.         } catch (NumberFormatException e) {
  47.             System.err.println("Pogresen vlez!");
  48.         }
  49.     }
  50.  
  51.     static List<Vraboten> removeLowerThan(List<Vraboten> employees, int amount) {
  52.         List<Vraboten> company = new ArrayList<>();
  53.         for (Vraboten vraboten : employees) {
  54.             if (vraboten.getPlata() >= amount) {
  55.                 company.add(vraboten);
  56.             }
  57.         }
  58.         return company;
  59.     }
  60. }
  61.  
  62. class Vraboten implements Comparable<Vraboten> {
  63.     private int ID;
  64.     private int plata;
  65.  
  66.     public Vraboten(int ID, int plata) {
  67.         this.ID = ID;
  68.         this.plata = plata;
  69.     }
  70.  
  71.     public int getID() {
  72.         return ID;
  73.     }
  74.  
  75.     public int getPlata() {
  76.         return plata;
  77.     }
  78.  
  79.     @Override
  80.     public String toString() {
  81.         return String.format("%d %d", ID, plata);
  82.     }
  83.  
  84.     @Override
  85.     public int compareTo(Vraboten o) {
  86.         return Integer.compare(ID, o.ID);
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement