Advertisement
Guest User

Untitled

a guest
Jun 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.util.ArrayList;
  5. import java.util.Collections;
  6. import java.util.Comparator;
  7. import java.util.Scanner;
  8.  
  9.  
  10. public class Main {
  11. static ArrayList<Debt> debtList;
  12.  
  13.  
  14. public static void main(String[] args) {
  15. debtList = new ArrayList<>();
  16. Scanner scanner = new Scanner(System.in);
  17. loading();
  18. while(true) { // opcje
  19. System.out.println("opcje");
  20. System.out.println("wyswietl");
  21. int choice=1;
  22. choice=scanner.nextInt();
  23. if (choice== 0) {
  24. scanner.close();
  25. return;
  26. } else {
  27. sort();
  28. }
  29. }
  30. }
  31. public static void display() { //funkcja wyswietlania
  32. for( int i = 0; i < debtList.size(); i++) {
  33. System.out.println(debtList.get(i).getCountry()+debtList.get(i).getPer_capita());
  34. }
  35. }
  36. public static void sort() { //sortowanie
  37. Collections.sort(debtList, new Comparator<Debt>()
  38. {
  39. @Override
  40. public int compare(Debt d1, Debt d2)
  41. {
  42. if (d1.getPopulation() > d2.getPopulation()) {
  43. return 1;
  44. } if (d2.getPopulation() < d1.getPopulation()) {
  45. return -1;
  46. } else {
  47. return 0;
  48. }
  49.  
  50. //porownanie
  51. }
  52. });
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59. public static void loading() { //funkcja pobierania
  60.  
  61. try{
  62. File file = new File("debt.txt"); //pobieranie - rżnąć
  63. FileReader fileReader = new FileReader(file);
  64. BufferedReader bufferedReader = new BufferedReader(fileReader);
  65. String textLine;
  66. //Debt_List debt_list = new Debt_list("Debt1");
  67.  
  68.  
  69. while ((textLine = bufferedReader.readLine()) !=null) { //tak samo
  70. String [] dataTable = textLine.split(";"); //tak samo
  71. String country = dataTable [0]; //tyle stringow ile zmiennych
  72. String amountString = dataTable [1];
  73. String populationString = dataTable[2];
  74. int amount = Integer.parseInt(amountString); //zamiana na liczbe
  75. int population = Integer.parseInt(populationString);
  76.  
  77. Debt debt = new Debt(country, amount, population); //tworzenie obiektu
  78. debtList.add(debt);
  79. }
  80.  
  81. bufferedReader.close();
  82. } catch (Exception e) {
  83. System.out.println("Exception enocuntered while importing data from the source file ("+e+")"); // co jak jebnie
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement