Advertisement
DamSi

Untitled

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